headplane/app/layouts/shell.tsx

44 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 { getSession } from '~/utils/sessions.server';
2025-02-19 18:09:42 -05:00
import type { AppContext } from '~server/context/app';
import { hp_getConfig } from '~server/context/global';
// This loads the bare minimum for the application to function
// So we know that if context fails to load then well, oops?
export async function loader({ request }: LoaderFunctionArgs) {
const session = await getSession(request.headers.get('Cookie'));
if (!session.has('hsApiKey')) {
return redirect('/login');
}
const context = hp_getConfig();
2025-02-13 12:35:12 -05:00
const { mode, config } = hs_getConfig();
return {
2025-02-13 12:35:12 -05:00
config,
url: context.headscale.public_url ?? context.headscale.url,
2025-02-13 12:35:12 -05:00
configAvailable: mode !== 'no',
debug: context.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
);
}