headplane/app/routes/auth/logout.ts

30 lines
666 B
TypeScript
Raw Normal View History

2024-12-31 10:31:50 +05:30
import { type ActionFunctionArgs, redirect } from 'react-router';
2025-03-22 01:36:27 -04:00
import type { LoadContext } from '~/server';
2024-03-30 02:44:06 -04:00
2024-12-08 13:27:51 -05:00
export async function loader() {
2024-12-31 10:30:14 +05:30
return redirect('/machines');
2024-12-08 13:27:51 -05:00
}
2025-03-22 01:36:27 -04:00
export async function action({
request,
context,
}: ActionFunctionArgs<LoadContext>) {
try {
await context.sessions.auth(request);
} catch {
redirect('/login');
2025-03-22 01:36:27 -04:00
}
// 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, {
2024-03-30 02:44:06 -04:00
headers: {
'Set-Cookie': await context.sessions.destroySession(),
2024-12-31 10:30:14 +05:30
},
});
2024-03-30 02:44:06 -04:00
}