mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-08-04 04:35:19 +02:00
31 lines
733 B
TypeScript
31 lines
733 B
TypeScript
|
import { lucia } from "$lib/server/auth";
|
||
|
import { fail, redirect } from "@sveltejs/kit";
|
||
|
|
||
|
import type { Actions, PageServerLoad } from "./$types";
|
||
|
|
||
|
export const load: PageServerLoad = async (event) => {
|
||
|
if (event.locals.user)
|
||
|
return {
|
||
|
user: event.locals.user,
|
||
|
};
|
||
|
return {
|
||
|
user: null,
|
||
|
};
|
||
|
};
|
||
|
|
||
|
export const actions: Actions = {
|
||
|
default: async (event) => {
|
||
|
if (!event.locals.session) {
|
||
|
return fail(401);
|
||
|
}
|
||
|
|
||
|
await lucia.invalidateSession(event.locals.session.id);
|
||
|
const sessionCookie = lucia.createBlankSessionCookie();
|
||
|
event.cookies.set(sessionCookie.name, sessionCookie.value, {
|
||
|
path: ".",
|
||
|
...sessionCookie.attributes,
|
||
|
});
|
||
|
return redirect(302, "/login");
|
||
|
},
|
||
|
};
|