added stuff to middleware

This commit is contained in:
Ubuntu 2025-03-27 19:14:36 +00:00
parent 7d9148157f
commit c9023ea862

View file

@ -1,29 +1,32 @@
import { auth0 } from './lib/auth0';
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
import { NextRequest, NextResponse } from "next/server"
import { auth0 } from "@/lib/auth0"
export async function middleware(request: NextRequest) {
const res = await auth0.getSession(request);
const authRes = await auth0.middleware(request)
if (!res) {
// not logged in, redirect to Auth0 login
return Response.redirect(
new URL('/auth/login', request.url),
302
);
if (request.nextUrl.pathname.startsWith("/auth")) {
return authRes
}
return NextResponse.next();
const session = await auth0.getSession(request)
if (!session) {
// user is not authenticated, redirect to login page
return NextResponse.redirect(new URL("/auth/login", request.nextUrl.origin))
}
// the headers from the auth middleware should always be returned
return authRes
}
export const config = {
matcher: [
/*
* Match all paths except:
* - public files (_next, images, icons, etc.)
* - auth routes like /auth/login and /auth/callback
*/
'/((?!_next/static|_next/image|favicon.ico|auth/.*).*)',
],
};
// export const config = {
// matcher: [
// /*
// * Match all paths except:
// * - public files (_next, images, icons, etc.)
// * - auth routes like /auth/login and /auth/callback
// */
// '/((?!_next/static|_next/image|favicon.ico|auth/.*).*)',
// ],
// };