Some checks failed
Tick / tick (push) Failing after 1s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
16 lines
735 B
TypeScript
16 lines
735 B
TypeScript
import { NextResponse, type NextRequest } from "next/server";
|
|
import { isValidSession, SESSION_COOKIE } from "@/lib/auth";
|
|
|
|
/** Toutes les pages demandent d'être connecté, sauf la connexion, les tâches planifiées et les fichiers de l'app. */
|
|
export async function proxy(request: NextRequest) {
|
|
if (await isValidSession(request.cookies.get(SESSION_COOKIE)?.value)) return NextResponse.next();
|
|
if (request.nextUrl.pathname.startsWith("/api/")) {
|
|
return NextResponse.json({ error: "Non connecté" }, { status: 401 });
|
|
}
|
|
return NextResponse.redirect(new URL("/login", request.url));
|
|
}
|
|
|
|
export const config = {
|
|
matcher: ["/((?!login|api/cron|manifest.webmanifest|sw.js|pwa-icon|apple-icon|icon|favicon.ico|_next).*)"],
|
|
};
|