headplane/app/routes/auth/oidc-callback.ts

18 lines
513 B
TypeScript
Raw Normal View History

2024-12-31 10:31:50 +05:30
import { type LoaderFunctionArgs, data } from 'react-router';
2024-12-31 10:30:14 +05:30
import { loadContext } from '~/utils/config/headplane';
import { finishOidc } from '~/utils/oidc';
2024-12-08 13:27:51 -05:00
export async function loader({ request }: LoaderFunctionArgs) {
try {
2024-12-31 10:30:14 +05:30
const context = await loadContext();
2024-12-08 13:27:51 -05:00
if (!context.oidc) {
2024-12-31 10:30:14 +05:30
throw new Error('An invalid OIDC configuration was provided');
2024-12-08 13:27:51 -05:00
}
2024-12-31 10:30:14 +05:30
return finishOidc(context.oidc, request);
2024-12-08 13:27:51 -05:00
} catch (error) {
// Gracefully present OIDC errors
2024-12-31 10:30:14 +05:30
return data({ error }, { status: 500 });
2024-12-08 13:27:51 -05:00
}
}