Skip to content

Commit

Permalink
Delete the user's auth cookie if it's missing or invalid (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
franknoirot authored Apr 2, 2024
1 parent cf66900 commit d29fa37
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/hooks.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ export const handle = async ({ event, resolve }) => {
})
.then((res) => res.json())
.catch((e) => {
throw error(500, e)
// If the user had a token but there was an error fetching the user,
//delete the token, because it was likely revoked or expired
console.error('Error fetching user:', e)
event.cookies.delete(AUTH_COOKIE_NAME, { domain, path: '/' })
throw redirect(303, '/')
})

if (!currentUser) {
Expand Down

0 comments on commit d29fa37

Please sign in to comment.