17 lines
499 B
TypeScript
17 lines
499 B
TypeScript
export default defineNuxtRouteMiddleware((to, from) => {
|
|
// Skip auth check on the login page itself
|
|
if (to.path === '/login') {
|
|
return
|
|
}
|
|
|
|
// Check for the access_token cookie
|
|
const tokenCookie = useCookie('access_token')
|
|
if (!tokenCookie.value) {
|
|
return navigateTo('/login')
|
|
}
|
|
|
|
// If the store is already initialized, check isAuthenticated
|
|
// Otherwise, the token cookie presence is sufficient for the guard
|
|
// The store's init() will validate the token on app mount
|
|
})
|