feat(middleware): autorizzazione a matrice + redirect per ruolo

This commit is contained in:
2026-07-05 21:47:24 +02:00
parent e87a464090
commit db92fc9c02
+2 -2
View File
@@ -1,6 +1,6 @@
import { defineMiddleware } from 'astro:middleware'; import { defineMiddleware } from 'astro:middleware';
import { getDb } from './lib/db'; 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) => { export const onRequest = defineMiddleware((context, next) => {
const { pathname } = context.url; const { pathname } = context.url;
@@ -26,7 +26,7 @@ export const onRequest = defineMiddleware((context, next) => {
status: 403, headers: { 'Content-Type': 'application/json' }, status: 403, headers: { 'Content-Type': 'application/json' },
}); });
} }
return context.redirect('/admin/content'); return context.redirect(landingFor(user.role));
} }
context.locals.user = user; context.locals.user = user;