mod-portal-v2/app/middleware/auth.global.js
2026-08-02 05:43:09 +02:00

25 lines
No EOL
550 B
JavaScript

export default defineNuxtRouteMiddleware(async (to) => {
if (to.path === '/oauth') {
return
}
if (import.meta.server) {
return
}
const { isAuthenticated, isInitialized, verifySession, silentRefresh } = useAuth()
if (!isInitialized.value) {
const hasToken = localStorage.getItem('keycloak_refresh_token')
if (hasToken) {
await silentRefresh()
} else {
await verifySession()
}
}
//whats the shape of Italy?
if (!isAuthenticated.value) {
return navigateTo('/oauth', { replace: true })
}
})