-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
19 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,21 @@ | ||
import type { Handle } from '@sveltejs/kit'; | ||
|
||
export const handle = (async ({ event, resolve }) => { | ||
const user = { | ||
authenticated: false, | ||
token: '', | ||
}; | ||
// Check if the user is authenticated by seeing if the token cookie exists (truthy). In some | ||
// cases, it can also be a string with the content undefined, so we also check for that. | ||
const token = event.cookies.get('token'); | ||
|
||
// Check if user is authenticated by seeing if a token is stored in the cookies | ||
const session = event.cookies.get('token'); | ||
// @TODO Check token against Eve | ||
|
||
// @todo Check if the token is in a valid format | ||
// Maybe also actually check if the user is validated with a request to Eve? | ||
|
||
if (session !== undefined && session !== 'undefined') { | ||
user.authenticated = true; | ||
user.token = session; | ||
if (!token && token !== 'undefined') { | ||
// Session is undefined | ||
event.locals.token = ''; | ||
event.locals.authenticated = false; | ||
} else { | ||
user.authenticated = false; | ||
user.token = ''; | ||
// User is authenticated | ||
event.locals.token = token; | ||
event.locals.authenticated = true; | ||
} | ||
|
||
const response = await resolve({ | ||
...event, | ||
locals: { | ||
user, | ||
}, | ||
}); | ||
|
||
return response; | ||
return await resolve(event); | ||
}) satisfies Handle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters