25 lines
No EOL
550 B
JavaScript
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 })
|
|
}
|
|
}) |