feat(middleware): autorizzazione a matrice + redirect per ruolo
This commit is contained in:
+2
-2
@@ -1,6 +1,6 @@
|
||||
import { defineMiddleware } from 'astro:middleware';
|
||||
import { getDb } from './lib/db';
|
||||
import { getSessionUser, SESSION_COOKIE, canAccessAdminPath } from './lib/auth';
|
||||
import { getSessionUser, SESSION_COOKIE, canAccessAdminPath, landingFor } from './lib/auth';
|
||||
|
||||
export const onRequest = defineMiddleware((context, next) => {
|
||||
const { pathname } = context.url;
|
||||
@@ -26,7 +26,7 @@ export const onRequest = defineMiddleware((context, next) => {
|
||||
status: 403, headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
||||
return context.redirect('/admin/content');
|
||||
return context.redirect(landingFor(user.role));
|
||||
}
|
||||
|
||||
context.locals.user = user;
|
||||
|
||||
Reference in New Issue
Block a user