2026-08-02 00:16:30 +02:00
|
|
|
export default defineNuxtRouteMiddleware(async (to) => {
|
2026-08-02 05:43:09 +02:00
|
|
|
if (to.path === '/oauth') {
|
|
|
|
|
return
|
|
|
|
|
}
|
2026-08-02 00:16:30 +02:00
|
|
|
|
2026-08-02 05:43:09 +02:00
|
|
|
if (import.meta.server) {
|
2026-08-02 00:16:30 +02:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-03 05:39:08 +02:00
|
|
|
const { isAuthenticated, isInitialized, initializeAuth } = useAuth()
|
2026-08-02 00:16:30 +02:00
|
|
|
|
|
|
|
|
if (!isInitialized.value) {
|
2026-08-03 05:39:08 +02:00
|
|
|
await initializeAuth({ redirectTo: '/oauth', replace: true })
|
2026-08-02 00:16:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!isAuthenticated.value) {
|
|
|
|
|
return navigateTo('/oauth', { replace: true })
|
|
|
|
|
}
|
|
|
|
|
})
|