From bdbae695d6fd70e57c1714462bcb69996cc9c23d Mon Sep 17 00:00:00 2001 From: Yunus Date: Tue, 3 Dec 2024 15:51:24 +0700 Subject: [PATCH] Add auto redirect to home if token cannot be validated --- docker-compose.env | 1 - server/middleware/auth-middleware.ts | 11 +++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docker-compose.env b/docker-compose.env index 10d5371..45e3509 100644 --- a/docker-compose.env +++ b/docker-compose.env @@ -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= diff --git a/server/middleware/auth-middleware.ts b/server/middleware/auth-middleware.ts index 6d4e01c..bdf538d 100644 --- a/server/middleware/auth-middleware.ts +++ b/server/middleware/auth-middleware.ts @@ -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')