mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 07:51:02 +00:00
25 lines
706 B
TypeScript
25 lines
706 B
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
|
|
const PUBLIC_PATHS = ['/login'];
|
|
|
|
export function middleware(request: NextRequest) {
|
|
const { pathname } = request.nextUrl;
|
|
|
|
if (PUBLIC_PATHS.some((p) => pathname.startsWith(p))) {
|
|
return NextResponse.next();
|
|
}
|
|
|
|
// Token is stored in localStorage (client-side only), so middleware can't
|
|
// read it directly. We use a cookie set on login as the server-side signal.
|
|
const token = request.cookies.get('auth_token')?.value;
|
|
if (!token) {
|
|
return NextResponse.redirect(new URL('/login', request.url));
|
|
}
|
|
|
|
return NextResponse.next();
|
|
}
|
|
|
|
export const config = {
|
|
matcher: ['/((?!_next/static|_next/image|favicon.ico|api).*)'],
|
|
};
|