initial
This commit is contained in:
7
apps/client/middleware/01.slash.global.ts
Normal file
7
apps/client/middleware/01.slash.global.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export default defineNuxtRouteMiddleware(async (to, from) => {
|
||||
if (to.path === '/')
|
||||
return navigateTo('/projects')
|
||||
|
||||
if (to.path !== '/' && to.path.endsWith('/'))
|
||||
return navigateTo(to.path.slice(0, -1))
|
||||
})
|
||||
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)
|
||||
}
|
||||
}
|
||||
})
|
||||
6
apps/client/middleware/auth.ts
Normal file
6
apps/client/middleware/auth.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export default defineNuxtRouteMiddleware(async (to, from) => {
|
||||
const { authenticated } = useAuth()
|
||||
|
||||
if (!authenticated.value)
|
||||
return navigateTo('/login')
|
||||
})
|
||||
6
apps/client/middleware/guest-only.ts
Normal file
6
apps/client/middleware/guest-only.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export default defineNuxtRouteMiddleware(() => {
|
||||
const { authenticated } = useAuth()
|
||||
|
||||
if (authenticated.value)
|
||||
return navigateTo('/projects')
|
||||
})
|
||||
Reference in New Issue
Block a user