first commit
This commit is contained in:
11
app/middleware/admin.ts
Normal file
11
app/middleware/admin.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export default defineNuxtRouteMiddleware((to, from) => {
|
||||
const { status, data } = useAuth();
|
||||
|
||||
if (status.value !== 'authenticated') {
|
||||
return navigateTo('/auth/login?callbackUrl=' + to.fullPath);
|
||||
}
|
||||
|
||||
if (!data.value?.user?.is_admin) {
|
||||
return navigateTo('/');
|
||||
}
|
||||
});
|
||||
8
app/middleware/guest-only.ts
Normal file
8
app/middleware/guest-only.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
// Middleware to redirect authenticated users away from guest-only pages
|
||||
export default defineNuxtRouteMiddleware((to, from) => {
|
||||
const { status } = useAuth();
|
||||
|
||||
if (status.value === 'authenticated') {
|
||||
return navigateTo('/');
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user