Prepare Kalendartool for MPM and disable invites

This commit is contained in:
Kühn
2026-10-08 15:06:22 +02:00
parent bc49c3074e
commit 556202575e
50 changed files with 905 additions and 836 deletions

View File

@@ -45,6 +45,27 @@ function isPublicPath(pathname: string): boolean {
export async function middleware(request: NextRequest) {
const { pathname } = request.nextUrl;
if (process.env.MPM_AUTH_MODE === 'true') {
const userId = request.headers.get('x-kalendartool-mpm-user-id');
const role = request.headers.get('x-kalendartool-mpm-role');
if (userId && role && ['ADMIN', 'USER'].includes(role)) {
const basePath = (process.env.HUB_BASE_PATH ?? '').replace(/\/$/, '');
const localPath = basePath && pathname.startsWith(basePath)
? pathname.slice(basePath.length) || '/'
: pathname;
if (['/login', '/register', '/forgot-password', '/auth/hub'].includes(localPath)) {
const dashboardUrl = request.nextUrl.clone();
dashboardUrl.pathname = `${basePath}/dashboard`;
return NextResponse.redirect(dashboardUrl);
}
if (localPath.startsWith('/api/auth/')) {
return NextResponse.json({ statusCode: 404, message: 'Nicht gefunden' }, { status: 404 });
}
return NextResponse.next();
}
return NextResponse.json({ statusCode: 401, message: 'Nicht authentifiziert' }, { status: 401 });
}
if (isPublicPath(pathname)) {
return NextResponse.next();
}
@@ -74,4 +95,4 @@ export async function middleware(request: NextRequest) {
export const config = {
// Alles ausser statischen Dateien.
matcher: ['/((?!favicon.ico|.*\\.(?:png|jpg|jpeg|svg|ico|webp|txt)).*)'],
};
};