import { Cog8ToothIcon, CpuChipIcon, GlobeAltIcon, LockClosedIcon, ServerStackIcon, UsersIcon } from '@heroicons/react/24/outline' import { type LoaderFunctionArgs, redirect } from '@remix-run/node' import { Outlet } from '@remix-run/react' import TabLink from '~/components/TabLink' import { HeadscaleError, pull } from '~/utils/headscale' import { destroySession, getSession } from '~/utils/sessions' export async function loader({ request }: LoaderFunctionArgs) { const session = await getSession(request.headers.get('Cookie')) if (!session.has('hsApiKey')) { return redirect('/login') } try { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion await pull('v1/apikey', session.get('hsApiKey')!) } catch (error) { if (error instanceof HeadscaleError) { console.error(error) // Safest to just redirect to login if we can't pull return redirect('/login', { headers: { // eslint-disable-next-line @typescript-eslint/naming-convention 'Set-Cookie': await destroySession(session) } }) } // Otherwise propagate to boundary throw error } // eslint-disable-next-line unicorn/no-null return null } export default function Layout() { return ( <>
) }