Start admin pages
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
export default defineNuxtRouteMiddleware((to) => {
|
||||
const { loggedIn, user } = useUserSession();
|
||||
|
||||
if (!loggedIn.value || !user.value || user.value?.role !== 'ADMIN') {
|
||||
const split = to.path.endsWith('/')
|
||||
? to.path.substring(0, to.path.length - 1).split('/')
|
||||
: to.path.split('/');
|
||||
|
||||
const localePath = useLocalePath();
|
||||
return navigateTo(
|
||||
!user.value
|
||||
? localePath(`/login?to=${to.path}`)
|
||||
: localePath(
|
||||
split.length > 1 ? split.slice(0, split.length - 1).join('/') : '/'
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user