Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

28 linesCodeBlameRaw
1import { data, redirect } from "react-router";
2
3import type { Route } from "./+types/auth-sso-saml";
4import { page } from "../lib/meta";
5import { clearErrorCookie, readErrorCookie } from "../lib/sso";
6import { sso } from "../lib/sso.server";
7import { SsoProblem } from "./auth-sso";
8
9export function meta({ params, ...args }: Route.MetaArgs) {
10 return page(args, { title: `Single sign-on · ${args.loaderData?.slug ?? params.owner} · g1t` });
11}
12
13/**
14 * The assertion consumer service, as a page: the provider's POST is
15 * answered by the Worker (workers/sso-saml.ts), which comes back here with
16 * why it did not work. Opened by itself, it starts again.
17 */
18export async function loader({ request, params }: Route.LoaderArgs) {
19 const key = params.owner.toLowerCase();
20 const slug = (await sso.summary(key).catch(() => null))?.slug || key;
21 const error = readErrorCookie(request.headers.get("cookie"));
22 if (!error) throw redirect(`/auth/sso/${slug}`);
23 return data({ slug, error }, { headers: { "set-cookie": clearErrorCookie() } });
24}
25
26export default function SsoSaml({ loaderData }: Route.ComponentProps) {
27 return <SsoProblem slug={loaderData.slug} error={loaderData.error} />;
28}