2
0
Fork 0
inspin.io/middleware/auth.js

18 lines
367 B
JavaScript
Raw Normal View History

2024-08-15 12:28:47 +00:00
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")
}
})