feat: respect context in server

This commit is contained in:
Aarnav Tale 2025-02-19 18:09:42 -05:00
parent 06049169a2
commit f5436f5ee3
No known key found for this signature in database
32 changed files with 359 additions and 204 deletions

View file

@ -1,17 +1,23 @@
import { type LoaderFunctionArgs, redirect } from 'react-router';
import { noContext } from '~/utils/log';
import { beginAuthFlow, getRedirectUri } from '~/utils/oidc';
import { commitSession, getSession } from '~/utils/sessions.server';
import { hp_getConfig } from '~/utils/state';
import type { AppContext } from '~server/context/app';
export async function loader({ request }: LoaderFunctionArgs) {
export async function loader({
request,
context,
}: LoaderFunctionArgs<AppContext>) {
const session = await getSession(request.headers.get('Cookie'));
if (session.has('hsApiKey')) {
return redirect('/machines');
}
// This is a hold-over from the old code
// TODO: Rewrite checkOIDC in the context loader
const { oidc } = hp_getConfig();
if (!context) {
throw noContext();
}
const { oidc } = context.context;
if (!oidc) {
throw new Error('An invalid OIDC configuration was provided');
}