mirror of
https://github.com/tale/headplane.git
synced 2026-08-06 04:07:41 +00:00
d2c4f5eb2b
* Cookies are now encrypted JWTs (GHSA-wrqq-v7qw-r5w7) * Authentication is stored in the SQLite database (auto-migrated) * Session logic is much cleaner
30 lines
666 B
TypeScript
30 lines
666 B
TypeScript
import { type ActionFunctionArgs, redirect } from 'react-router';
|
|
import type { LoadContext } from '~/server';
|
|
|
|
export async function loader() {
|
|
return redirect('/machines');
|
|
}
|
|
|
|
export async function action({
|
|
request,
|
|
context,
|
|
}: ActionFunctionArgs<LoadContext>) {
|
|
try {
|
|
await context.sessions.auth(request);
|
|
} catch {
|
|
redirect('/login');
|
|
}
|
|
|
|
// When API key is disabled, we need to explicitly redirect
|
|
// with a logout state to prevent auto login again.
|
|
const url = context.config.oidc?.disable_api_key_login
|
|
? '/login?s=logout'
|
|
: '/login';
|
|
|
|
return redirect(url, {
|
|
headers: {
|
|
'Set-Cookie': await context.sessions.destroySession(),
|
|
},
|
|
});
|
|
}
|