Refactor project structure and update dependencies
This commit is contained in:
8
nuxt/app/middleware/auth.ts
Normal file
8
nuxt/app/middleware/auth.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export default defineNuxtRouteMiddleware(() => {
|
||||
const nuxtApp = useNuxtApp()
|
||||
const auth = useAuthStore()
|
||||
|
||||
if (!auth.isLoggedIn) {
|
||||
return nuxtApp.runWithContext(() => navigateTo('/login'))
|
||||
}
|
||||
})
|
||||
8
nuxt/app/middleware/guest.ts
Normal file
8
nuxt/app/middleware/guest.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export default defineNuxtRouteMiddleware(() => {
|
||||
const nuxtApp = useNuxtApp()
|
||||
const auth = useAuthStore()
|
||||
|
||||
if (auth.isLoggedIn) {
|
||||
return nuxtApp.runWithContext(() => navigateTo('/'))
|
||||
}
|
||||
})
|
||||
16
nuxt/app/middleware/role-admin.ts
Normal file
16
nuxt/app/middleware/role-admin.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export default defineNuxtRouteMiddleware(() => {
|
||||
const nuxtApp = useNuxtApp()
|
||||
const auth = useAuthStore()
|
||||
|
||||
if (auth.isLoggedIn && !auth.user.roles.includes('admin')) {
|
||||
return nuxtApp.runWithContext(() => {
|
||||
useToast().add({
|
||||
icon: 'i-heroicons-exclamation-circle-solid',
|
||||
title: 'Access denied.',
|
||||
color: 'error',
|
||||
})
|
||||
|
||||
return navigateTo('/')
|
||||
})
|
||||
}
|
||||
})
|
||||
16
nuxt/app/middleware/role-user.ts
Normal file
16
nuxt/app/middleware/role-user.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export default defineNuxtRouteMiddleware(() => {
|
||||
const nuxtApp = useNuxtApp()
|
||||
const auth = useAuthStore()
|
||||
|
||||
if (auth.isLoggedIn && !auth.user.roles.includes('user')) {
|
||||
return nuxtApp.runWithContext(() => {
|
||||
useToast().add({
|
||||
icon: 'i-heroicons-exclamation-circle-solid',
|
||||
title: 'Access denied.',
|
||||
color: 'error',
|
||||
})
|
||||
|
||||
return navigateTo('/')
|
||||
})
|
||||
}
|
||||
})
|
||||
16
nuxt/app/middleware/verified.ts
Normal file
16
nuxt/app/middleware/verified.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export default defineNuxtRouteMiddleware(() => {
|
||||
const nuxtApp = useNuxtApp()
|
||||
const auth = useAuthStore()
|
||||
|
||||
if (auth.isLoggedIn && auth.user.must_verify_email) {
|
||||
return nuxtApp.runWithContext(() => {
|
||||
useToast().add({
|
||||
icon: 'i-heroicons-exclamation-circle-solid',
|
||||
title: 'Please confirm your email.',
|
||||
color: 'error',
|
||||
})
|
||||
|
||||
return navigateTo('/account/general')
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user