mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-21 13:59:36 +02:00
refactor: Handle authentication cookies in authHook
This commit is contained in:
parent
48b70b5bec
commit
2bb1d80a77
1 changed files with 7 additions and 1 deletions
|
@ -6,8 +6,14 @@ import { fetchCSRFToken, tryRefreshToken } from '$lib/index.server';
|
|||
export const authHook: Handle = async ({ event, resolve }) => {
|
||||
try {
|
||||
let authCookie = event.cookies.get('auth');
|
||||
let refreshCookie = event.cookies.get('refresh');
|
||||
|
||||
if (!authCookie) {
|
||||
if (!authCookie && !refreshCookie) {
|
||||
event.locals.user = null;
|
||||
return await resolve(event);
|
||||
}
|
||||
|
||||
if (!authCookie && refreshCookie) {
|
||||
event.locals.user = null;
|
||||
const token = await tryRefreshToken(event.cookies.get('refresh') || '');
|
||||
if (token) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue