Persist learn progress per user

This commit is contained in:
Remi
2025-09-18 23:28:02 +02:00
committed by itsrubberduck
parent b6785e9f05
commit 6dbfe07d2b
6 changed files with 231 additions and 3 deletions

View File

@@ -0,0 +1,21 @@
import { defineNuxtRouteMiddleware, navigateTo } from '#app'
import { useAuthStore } from '~/stores/auth'
export default defineNuxtRouteMiddleware(async (to) => {
const auth = useAuthStore()
if (!auth.accessToken) {
await auth.tryRefresh().catch(() => false)
}
if (!auth.initialized) {
await auth.fetchUser().catch(() => null)
} else if (!auth.user) {
await auth.fetchUser().catch(() => null)
}
if (!auth.user) {
const redirect = encodeURIComponent(to.fullPath || '/')
return navigateTo(`/login?redirect=${redirect}`)
}
})