Kovi
Kovi
NNuxt
Created by Kovi on 7/2/2024 in #❓・help
client side navigation to a server side page will run the authorization middleware in the browser
I made a more detailed description of the issue, but I was unable to close/delete this one: https://discord.com/channels/473401852243869706/1258398982347034757
4 replies
NNuxt
Created by Kovi on 7/2/2024 in #❓・help
client side navigation to a server side page will run the authorization middleware in the browser
the auth,global.ts looks like this (there are some dummy variables)
import { useAuthStore } from "@/stores/auth"
export default defineNuxtRouteMiddleware((to, from) => {
const authStore = useAuthStore()

var role = 'user'
var hasSubscription = true

if (to.path.startsWith('/admin') && !(authStore.isAuthenticated && role === 'admin')) {
return abortNavigation({ statusCode: 401, message: 'Unauthorized', fatal: true })
}

if (to.path.startsWith('/tco') && !(authStore.isAuthenticated && hasSubscription)) {
return abortNavigation({ statusCode: 401, message: 'Unauthorized', fatal: true })
}

})
import { useAuthStore } from "@/stores/auth"
export default defineNuxtRouteMiddleware((to, from) => {
const authStore = useAuthStore()

var role = 'user'
var hasSubscription = true

if (to.path.startsWith('/admin') && !(authStore.isAuthenticated && role === 'admin')) {
return abortNavigation({ statusCode: 401, message: 'Unauthorized', fatal: true })
}

if (to.path.startsWith('/tco') && !(authStore.isAuthenticated && hasSubscription)) {
return abortNavigation({ statusCode: 401, message: 'Unauthorized', fatal: true })
}

})
4 replies
NNuxt
Created by Kovi on 7/2/2024 in #❓・help
client side navigation to a server side page will run the authorization middleware in the browser
No description
4 replies