A link to a workspace's Agents or Integrations asks a signed-out visitor to sign in and then opens it, as Chat and Docs do, instead of a 404
3 files+11−80/3 viewed
| 16 | 16 | import { page } from "../../lib/meta"; | |
| 17 | 17 | import { useRefreshWhile } from "../../lib/refresh"; | |
| 18 | 18 | import { workspaceAgents } from "../../lib/services.server"; | |
| 19 | − | import { getViewer, roleIn } from "../../lib/session.server"; | |
| 19 | + | import { requireUser, roleIn } from "../../lib/session.server"; | |
| 20 | 20 | import { money } from "../../lib/usage"; | |
| 21 | 21 | ||
| 22 | 22 | export function meta({ params, ...args }: Route.MetaArgs) { | |
| ⋯ | |||
| 24 | 24 | } | |
| 25 | 25 | ||
| 26 | 26 | /** Agents mode's front page: the budget, what is waiting and working, the roster, and where the month went. */ | |
| 27 | − | export async function loader({ params, context }: Route.LoaderArgs): Promise<{ overview: AgentsOverview | null }> { | |
| 28 | − | const viewer = getViewer(context); | |
| 27 | + | export async function loader({ params, context, request }: Route.LoaderArgs): Promise<{ overview: AgentsOverview | null }> { | |
| 28 | + | // Signed out, sign in first (as Chat and Docs do), rather than a 404. | |
| 29 | + | const viewer = requireUser(context, request); | |
| 29 | 30 | if (!viewer || !roleIn(viewer, params.owner)) throw data(null, { status: 404 }); | |
| 30 | 31 | return { overview: await readOrNull(workspaceAgents.overview(params.owner.toLowerCase(), viewer)) }; | |
| 31 | 32 | } | |
| 6 | 6 | ||
| 7 | 7 | import type { Route } from "./+types/layout"; | |
| 8 | 8 | import { workspaceAgents } from "../../../lib/services.server"; | |
| 9 | − | import { getViewer, roleIn } from "../../../lib/session.server"; | |
| 9 | + | import { requireUser, roleIn } from "../../../lib/session.server"; | |
| 10 | 10 | ||
| 11 | 11 | /** | |
| 12 | 12 | * Agents mode: the workspace's agents, for its sidebar, and how many live | |
| ⋯ | |||
| 14 | 14 | */ | |
| 15 | 15 | export type AgentsLayoutData = { slug: string; agents: WorkspaceAgent[] | null; live: Record<string, number> }; | |
| 16 | 16 | ||
| 17 | − | export async function loader({ params, context }: Route.LoaderArgs): Promise<AgentsLayoutData> { | |
| 18 | − | const viewer = getViewer(context); | |
| 17 | + | export async function loader({ params, context, request }: Route.LoaderArgs): Promise<AgentsLayoutData> { | |
| 18 | + | // Signed out, sign in first (as Chat and Docs do), rather than a 404. | |
| 19 | + | const viewer = requireUser(context, request); | |
| 19 | 20 | if (!roleIn(viewer, params.owner)) throw data(null, { status: 404 }); | |
| 20 | 21 | const slug = params.owner.toLowerCase(); | |
| 21 | 22 | const [listed, live] = await Promise.all([ | |
| 10 | 10 | import { integrationsSection } from "../../lib/integration-sections"; | |
| 11 | 11 | import { page } from "../../lib/meta"; | |
| 12 | 12 | import { integrations, webhooks } from "../../lib/services.server"; | |
| 13 | − | import { getViewer, roleIn } from "../../lib/session.server"; | |
| 13 | + | import { requireUser, roleIn } from "../../lib/session.server"; | |
| 14 | 14 | ||
| 15 | 15 | export function meta({ params, ...args }: Route.MetaArgs) { | |
| 16 | 16 | return page(args, { title: `Integrations · ${params.owner} · g1t` }); | |
| ⋯ | |||
| 23 | 23 | * GitHub import, webhooks); this page only finds them. | |
| 24 | 24 | */ | |
| 25 | 25 | export async function loader({ params, context, request }: Route.LoaderArgs) { | |
| 26 | − | const viewer = getViewer(context); | |
| 26 | + | // Signed out, sign in first (as Chat and Docs do), rather than a 404. | |
| 27 | + | const viewer = requireUser(context, request); | |
| 27 | 28 | const role = roleIn(viewer, params.owner); | |
| 28 | 29 | if (!role || !viewer) throw new Response(null, { status: 404 }); | |
| 29 | 30 | const slug = params.owner.toLowerCase(); | |