mirror of
https://github.com/OpenSquawk/OpenSquawk
synced 2026-08-05 08:55:54 +08:00
Finalize admin tools and transmission fault flow
This commit is contained in:
19
app/middleware/require-admin.ts
Normal file
19
app/middleware/require-admin.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { defineNuxtRouteMiddleware, navigateTo } from '#app'
|
||||
import { useAuthStore } from '~/stores/auth'
|
||||
|
||||
export default defineNuxtRouteMiddleware(async (to) => {
|
||||
const auth = useAuthStore()
|
||||
|
||||
if (!auth.initialized) {
|
||||
await auth.fetchUser().catch(() => null)
|
||||
}
|
||||
|
||||
if (!auth.user) {
|
||||
const redirect = encodeURIComponent(to.fullPath || '/admin')
|
||||
return navigateTo(`/login?redirect=${redirect}`)
|
||||
}
|
||||
|
||||
if (!['admin', 'dev'].includes(auth.user.role)) {
|
||||
return navigateTo('/')
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user