mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-18 14:01:04 +00:00
feat: add auto logout
This commit is contained in:
parent
f4080f75b7
commit
87c35107ce
1 changed files with 12 additions and 3 deletions
|
|
@ -1,10 +1,19 @@
|
|||
import type { LayoutServerLoad } from './$types';
|
||||
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import { apiWhoami } from '$lib/@api/admin';
|
||||
|
||||
export const load: LayoutServerLoad = ({ cookies }) => {
|
||||
export const load: LayoutServerLoad = async ({ cookies, fetch }) => {
|
||||
const isAuthenticated = cookies.get('id');
|
||||
if (!isAuthenticated) {
|
||||
throw redirect(302, '/admin/auth/login');
|
||||
|
||||
if (isAuthenticated) {
|
||||
const whoami = await apiWhoami(fetch).catch((e) => {
|
||||
throw redirect(302, '/admin/auth/logout');
|
||||
});
|
||||
return {
|
||||
whoami: whoami
|
||||
};
|
||||
} else {
|
||||
throw redirect(302, '/admin/auth/logout');
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue