30 lines
860 B
TypeScript
30 lines
860 B
TypeScript
import { clearLoginFlowCookie, finishLogin } from "$lib/server/auth";
|
|
import { error, redirect } from "@sveltejs/kit";
|
|
import type { RequestHandler } from "./$types";
|
|
|
|
export const GET: RequestHandler = async (event) => {
|
|
const providerError = event.url.searchParams.get("error");
|
|
if (providerError) {
|
|
clearLoginFlowCookie(event.cookies);
|
|
const providerErrorDescription =
|
|
event.url.searchParams.get("error_description");
|
|
throw error(
|
|
400,
|
|
providerErrorDescription
|
|
? `${providerError}: ${providerErrorDescription}`
|
|
: `OIDC callback failed: ${providerError}`,
|
|
);
|
|
}
|
|
|
|
let returnTo: string;
|
|
try {
|
|
returnTo = await finishLogin(event);
|
|
} catch (cause) {
|
|
throw error(
|
|
400,
|
|
cause instanceof Error ? cause.message : "OIDC callback failed",
|
|
);
|
|
}
|
|
|
|
throw redirect(303, returnTo);
|
|
};
|