Ajout des fichiers de l'application

This commit is contained in:
Rampeur
2025-08-07 08:12:11 +02:00
parent 16fc6b69a6
commit 8da4b7cb28
193 changed files with 372196 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
import { NextRequest, NextResponse } from "next/server";
import { getSession } from "./utils/auth/session";
export const config = {
matcher: ["/((?!api|_next/static|_next/image|.*\\.png$).*)"],
};
const publicRoutes = [
/^\/article\/[^\/]+?\/?$/, // /article/sample-slug
/^\/login\/?$/,
/^\/profile\/[^\/]+?\/?$/, // /profile/sample-username
/^\/profile\/[^\/]+?\/favorites\/?$/, // /profile/sample-username/favorites
/^\/register\/?$/,
/^\/$/,
] as const;
const isPublicRoutes = (pathname: string) => {
return publicRoutes.some((route) => route.test(pathname));
};
const isPrivateRoutes = (pathname: string) => {
return !isPublicRoutes(pathname);
};
const middleware = async (req: NextRequest) => {
const session = await getSession();
if (isPrivateRoutes(req.nextUrl.pathname) && session == null) {
return NextResponse.redirect(new URL("/login", req.nextUrl));
}
return NextResponse.next();
};
export default middleware;