feat: add TypeScript definitions for next-auth session with accessToken and user details
Test Suite / test (24.15.0) (push) Has been cancelled

This commit is contained in:
Nils-Johan Gynther
2026-05-04 20:09:21 +02:00
parent afd2607000
commit ffe50e5151
135 changed files with 5 additions and 38 deletions
+33
View File
@@ -0,0 +1,33 @@
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).*)'],
};