26 lines
756 B
TypeScript
26 lines
756 B
TypeScript
|
|
import { NextRequest, NextResponse } from "next/server";
|
||
|
|
|
||
|
|
export function middleware(request: NextRequest) {
|
||
|
|
// Simple check for auth routes or static files
|
||
|
|
if (
|
||
|
|
request.nextUrl.pathname.startsWith('/api/auth') ||
|
||
|
|
request.nextUrl.pathname.startsWith('/_next') ||
|
||
|
|
request.nextUrl.pathname === '/favicon.ico'
|
||
|
|
) {
|
||
|
|
return NextResponse.next();
|
||
|
|
}
|
||
|
|
|
||
|
|
const token = request.cookies.get('next-auth.session-token') ||
|
||
|
|
request.cookies.get('__Secure-next-auth.session-token');
|
||
|
|
|
||
|
|
if (!token && request.nextUrl.pathname !== '/') {
|
||
|
|
return NextResponse.redirect(new URL('/', request.url));
|
||
|
|
}
|
||
|
|
|
||
|
|
return NextResponse.next();
|
||
|
|
}
|
||
|
|
|
||
|
|
export const config = {
|
||
|
|
matcher: ['/((?!api/auth|_next/static|_next/image|favicon.ico).*)'],
|
||
|
|
};
|