headplane/app/routes/auth/logout.ts

23 lines
500 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>) {
const session = await context.sessions.auth(request);
if (!session.has('api_key')) {
return redirect('/login');
}
2024-12-08 13:27:51 -05:00
return redirect('/login', {
2024-03-30 02:44:06 -04:00
headers: {
2025-03-22 01:36:27 -04:00
'Set-Cookie': await context.sessions.destroy(session),
2024-12-31 10:30:14 +05:30
},
});
2024-03-30 02:44:06 -04:00
}