Skip to content

Commit

Permalink
Add auto redirect to home if token cannot be validated
Browse files Browse the repository at this point in the history
  • Loading branch information
yunusefendi52 committed Dec 3, 2024
1 parent 75bac72 commit bdbae69
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 0 additions & 1 deletion docker-compose.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ NUXT_S3_ENDPOINT=https://s3endpoint
NUXT_S3_ACCESS_KEY_ID=cd28e489b9a94daa893fa77b81fe82d4
NUXT_S3_SECRET_ACCESS_KEY=f98f62c0535f43ce954ad23e3a4c7a69
NUXT_JWT_KEY=36b3a2590d734b4aaf31bca4484647f6
NUXT_SIGNIN_KEY=a9a9e44d5344448789813e3ca7014d0e
NUXT_PUBLIC_GOOGLE_CLIENT_ID=
NUXT_APP_MIGRATION_ENABLE=true
NUXT_APP_MIGRATION_DIR=
Expand Down
11 changes: 9 additions & 2 deletions server/middleware/auth-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,16 @@ export default defineEventHandler(async (event) => {
}
}
}
catch (e) {
console.log(e)
catch (e: any) {
console.error(e)
deleteCookie(event, cookieAuthKey)
if (e.code === 'ERR_JWS_SIGNATURE_VERIFICATION_FAILED') {
console.warn('Failed to verify jwt in auth, different key?')
const path = event.path
if (path !== '/') {
await sendRedirect(event, '/')
}
}
}
} else {
console.log('user not logged in')
Expand Down

0 comments on commit bdbae69

Please sign in to comment.