initial
This commit is contained in:
17
apps/client/middleware/02.load-user.global.ts
Normal file
17
apps/client/middleware/02.load-user.global.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import type { User } from '~/composables/use-auth'
|
||||
|
||||
export default defineNuxtRouteMiddleware(async (to, from) => {
|
||||
const session = useCookie('session')
|
||||
const { authenticated, user } = useAuth()
|
||||
|
||||
if (session.value && !authenticated.value) {
|
||||
try {
|
||||
user.value = await $api<User>('/users/current', {
|
||||
method: 'get',
|
||||
})
|
||||
}
|
||||
catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user