Init
This commit is contained in:
8
nuxt/middleware/auth.ts
Normal file
8
nuxt/middleware/auth.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export default defineNuxtRouteMiddleware((to, from) => {
|
||||
const nuxtApp = useNuxtApp()
|
||||
const auth = useAuthStore()
|
||||
|
||||
if (!auth.isLoggedIn) {
|
||||
return nuxtApp.runWithContext(() => navigateTo('/login'))
|
||||
}
|
||||
})
|
||||
8
nuxt/middleware/guest.ts
Normal file
8
nuxt/middleware/guest.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export default defineNuxtRouteMiddleware((to, from) => {
|
||||
const nuxtApp = useNuxtApp()
|
||||
const auth = useAuthStore()
|
||||
|
||||
if (auth.isLoggedIn) {
|
||||
return nuxtApp.runWithContext(() => navigateTo('/'))
|
||||
}
|
||||
})
|
||||
16
nuxt/middleware/role-admin.ts
Normal file
16
nuxt/middleware/role-admin.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export default defineNuxtRouteMiddleware((to, from) => {
|
||||
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: "red",
|
||||
});
|
||||
|
||||
return navigateTo('/')
|
||||
})
|
||||
}
|
||||
})
|
||||
16
nuxt/middleware/role-user.ts
Normal file
16
nuxt/middleware/role-user.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export default defineNuxtRouteMiddleware((to, from) => {
|
||||
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: "red",
|
||||
});
|
||||
|
||||
return navigateTo('/')
|
||||
})
|
||||
}
|
||||
})
|
||||
16
nuxt/middleware/verified.ts
Normal file
16
nuxt/middleware/verified.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export default defineNuxtRouteMiddleware((to, from) => {
|
||||
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: "red",
|
||||
});
|
||||
|
||||
return navigateTo('/account/general')
|
||||
})
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user