18 lines
367 B
JavaScript
18 lines
367 B
JavaScript
|
export default defineNuxtRouteMiddleware(async (to, _from) => {
|
||
|
|
||
|
const { fetchUser, setUser } = useDirectusAuth()
|
||
|
const { refreshTokens } = useDirectusToken()
|
||
|
|
||
|
const user = useDirectusUser()
|
||
|
|
||
|
if (!user.value) {
|
||
|
const user = await fetchUser()
|
||
|
setUser(user.value)
|
||
|
refreshTokens()
|
||
|
}
|
||
|
|
||
|
if (!user.value) {
|
||
|
return navigateTo("/login")
|
||
|
}
|
||
|
|
||
|
})
|