headplane/app/layouts/shell.tsx

51 lines
1.1 KiB
TypeScript
Raw Normal View History

2025-02-13 12:35:12 -05:00
import {
LoaderFunctionArgs,
Outlet,
redirect,
useLoaderData,
} from 'react-router';
import Footer from '~/components/Footer';
2025-02-13 12:35:12 -05:00
import Header from '~/components/Header';
2025-02-19 18:09:42 -05:00
import { hs_getConfig } from '~/utils/config/loader';
import { noContext } from '~/utils/log';
import { getSession } from '~/utils/sessions.server';
2025-02-19 18:09:42 -05:00
import type { AppContext } from '~server/context/app';
// This loads the bare minimum for the application to function
// So we know that if context fails to load then well, oops?
2025-02-19 18:09:42 -05:00
export async function loader({
request,
context,
}: LoaderFunctionArgs<AppContext>) {
const session = await getSession(request.headers.get('Cookie'));
if (!session.has('hsApiKey')) {
return redirect('/login');
}
2025-02-19 18:09:42 -05:00
if (!context) {
throw noContext();
}
const ctx = context.context;
2025-02-13 12:35:12 -05:00
const { mode, config } = hs_getConfig();
return {
2025-02-13 12:35:12 -05:00
config,
2025-02-19 18:09:42 -05:00
url: ctx.headscale.public_url ?? ctx.headscale.url,
2025-02-13 12:35:12 -05:00
configAvailable: mode !== 'no',
2025-02-19 18:09:42 -05:00
debug: ctx.debug,
user: session.get('user'),
};
}
export default function Shell() {
const data = useLoaderData<typeof loader>();
return (
<>
<Header {...data} />
<Outlet />
<Footer {...data} />
</>
2025-02-13 12:35:12 -05:00
);
}