Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Added Private Route Array #69

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
7 changes: 6 additions & 1 deletion src/server/authMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ type MiddlewareOptions = {
// - process.env.SIGN_IN_ROUTE or /sign-in if not provided
// - process.env.SIGN_UP_ROUTE or /sign-up if not provided
publicRoutes?: string[];

// An array of private routes that require authentication
// If privateRoutes is defined, routes not listed in this array will default to public routes
privateRoutes?: string[];
gaokevin1 marked this conversation as resolved.
Show resolved Hide resolved
};

const getSessionJwt = (req: NextRequest): string | undefined => {
Expand All @@ -45,8 +49,9 @@ const isPublicRoute = (req: NextRequest, options: MiddlewareOptions) => {
req.nextUrl.pathname
);
const isPublic = options.publicRoutes?.includes(req.nextUrl.pathname);
const isPrivate = options.privateRoutes?.includes(req.nextUrl.pathname);

return isDefaultPublicRoute || isPublic;
return isDefaultPublicRoute || isPublic || !isPrivate;
gaokevin1 marked this conversation as resolved.
Show resolved Hide resolved
};

const addSessionToHeadersIfExists = (
Expand Down
Loading