Skip to content

Commit

Permalink
fix regex Pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
mahmodghnaj committed Nov 26, 2023
1 parent 7ec9bc0 commit 7343d20
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions middleware/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@ const pathWithoutAuth = [
// Define an array of public paths
const publicPath = ["/auth/confirm-email"];

const regexPattern = /^(?!\/(api|_next\/(static|image)|favicon\.ico)).*/;

// Create a middleware factory named "authorization"
export const authorization: MiddlewareFactory = (next: NextMiddleware) => {
return async (request: NextRequest, _next: NextFetchEvent) => {
// Extract the pathname from the request URL
const pathname = request.nextUrl.pathname;

// Check if the path is for static assets (e.g., /_next/ or favicon.ico)
if (pathname.startsWith("/_next/") || pathname.includes("favicon.ico")) {
// Allow these requests to continue without further processing
return NextResponse.next();
}
if (!regexPattern.test(pathname)) return NextResponse.next();

// Check if the user is authenticated
const isAuth = await isAuthenticated(request);
Expand Down

0 comments on commit 7343d20

Please sign in to comment.