b913a2bf90
Refs gitea:Adriano/AI-OS#310 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
48 lines
1.6 KiB
Diff
48 lines
1.6 KiB
Diff
# Review package: e87a464..db92fc9
|
|
|
|
## Commits
|
|
db92fc9 feat(middleware): autorizzazione a matrice + redirect per ruolo
|
|
|
|
## Files changed
|
|
src/middleware.ts | 4 ++--
|
|
1 file changed, 2 insertions(+), 2 deletions(-)
|
|
|
|
## Diff
|
|
diff --git a/src/middleware.ts b/src/middleware.ts
|
|
index bed89db..c8c53b5 100644
|
|
--- a/src/middleware.ts
|
|
+++ b/src/middleware.ts
|
|
@@ -1,13 +1,13 @@
|
|
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;
|
|
const isProtected =
|
|
(pathname.startsWith('/admin') && pathname !== '/admin/login') ||
|
|
pathname.startsWith('/api/admin');
|
|
if (!isProtected) return next();
|
|
|
|
const token = context.cookies.get(SESSION_COOKIE)?.value;
|
|
const user = token ? getSessionUser(getDb(), token) : null;
|
|
@@ -19,16 +19,16 @@ export const onRequest = defineMiddleware((context, next) => {
|
|
}
|
|
return context.redirect('/admin/login');
|
|
}
|
|
|
|
if (!canAccessAdminPath(user.role, pathname)) {
|
|
if (pathname.startsWith('/api/')) {
|
|
return new Response(JSON.stringify({ error: 'Permessi insufficienti' }), {
|
|
status: 403, headers: { 'Content-Type': 'application/json' },
|
|
});
|
|
}
|
|
- return context.redirect('/admin/content');
|
|
+ return context.redirect(landingFor(user.role));
|
|
}
|
|
|
|
context.locals.user = user;
|
|
return next();
|
|
});
|