Skip to content

Commit

Permalink
fix(middleware): authorize landing page access to lambda user (#19)
Browse files Browse the repository at this point in the history
- refactor by adding public routes (gg dorian nice idea)
  • Loading branch information
dorian-grst authored Oct 11, 2024
1 parent 371b610 commit cc5ce5d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import type { NextRequest } from "next/server";

export function middleware(request: NextRequest) {
const accessToken = request.cookies.get("gists.access_token")?.value;
const publicRoutes = ["/", "/login"]; // Ajoutez ici d'autres routes publiques si nécessaire

if (!accessToken && !request.nextUrl.pathname.startsWith("/login")) {
if (!accessToken && !publicRoutes.includes(request.nextUrl.pathname)) {
return Response.redirect(new URL("/login", request.url));
}
}

export const config = {
matcher: ["/((?!api|_next/static|_next/image|.*\\.png$).*)"],
};
};

0 comments on commit cc5ce5d

Please sign in to comment.