From 8d1319164edfa3e0faf3e1aeb7dea703d66831b3 Mon Sep 17 00:00:00 2001 From: Irwan Cahyono Date: Fri, 8 Aug 2025 00:43:42 +0700 Subject: [PATCH] store --- middleware/auth.global.ts | 15 ++++++++++----- pages/auth/login.vue | 11 +++++++---- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/middleware/auth.global.ts b/middleware/auth.global.ts index 08c31f8..00a7d0f 100644 --- a/middleware/auth.global.ts +++ b/middleware/auth.global.ts @@ -1,11 +1,16 @@ export default defineNuxtRouteMiddleware((to, from) => { - const accessToken = useCookie('access_token').value; + try { + const accessToken = useCookie('access_token').value; - const isPublicRoute = - ['/auth/login'].includes(to.path) || - to.path.startsWith('/auth/activation/'); + const isPublicRoute = + ['/auth/login'].includes(to.path) || + to.path.startsWith('/auth/activation/'); - if (!accessToken && !isPublicRoute) { + if (!accessToken && !isPublicRoute) { + return navigateTo('/auth/login'); + } + } catch (error) { + console.error('Auth middleware error:', error); return navigateTo('/auth/login'); } }) \ No newline at end of file diff --git a/pages/auth/login.vue b/pages/auth/login.vue index 793851e..582bace 100644 --- a/pages/auth/login.vue +++ b/pages/auth/login.vue @@ -33,8 +33,10 @@ Logo - + + +