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 { 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;
|
||||||
|
|||||||
Reference in New Issue
Block a user