fix: ta bort middleware.ts (Next.js 16 anvander proxy.ts), uppdatera matcher

This commit is contained in:
Nils-Johan Gynther
2026-04-19 21:49:15 +02:00
parent b4d9e3dd5f
commit 8ab807aba2
2 changed files with 1 additions and 38 deletions
-37
View File
@@ -1,37 +0,0 @@
import { NextResponse } from 'next/server';
import { auth } from './auth';
export default auth((req) => {
const { pathname } = req.nextUrl;
// Alltid tillgängliga sidor
const publicPaths = ['/login', '/register'];
if (publicPaths.some((p) => pathname.startsWith(p))) {
return NextResponse.next();
}
// Om ej inloggad, omdirigera till /login
if (!req.auth) {
const loginUrl = new URL('/login', req.url);
loginUrl.searchParams.set('callbackUrl', pathname);
return NextResponse.redirect(loginUrl);
}
// Admin-sidor kräver admin-roll
if (pathname.startsWith('/admin')) {
const role = (req.auth.user as any)?.role;
if (role !== 'admin') {
return NextResponse.redirect(new URL('/', req.url));
}
}
return NextResponse.next();
});
export const config = {
matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
};
export const config = {
matcher: ['/((?!_next/static|_next/image|favicon.ico|api/auth).*)'],
};
+1 -1
View File
@@ -29,5 +29,5 @@ export default auth((req) => {
});
export const config = {
matcher: ['/((?!_next/static|_next/image|favicon.ico|api/auth).*)'],
matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
};