From 9fecc480e9aaaf5a044ae0eaba46d88a03474e56 Mon Sep 17 00:00:00 2001 From: Darya Umrikhina Date: Fri, 16 Aug 2024 01:54:19 +0400 Subject: [PATCH] Login:Src: add new headers for confirm pages --- packages/login/src/middleware.ts | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/login/src/middleware.ts b/packages/login/src/middleware.ts index 8986942ff9..d9ea85358c 100644 --- a/packages/login/src/middleware.ts +++ b/packages/login/src/middleware.ts @@ -49,9 +49,21 @@ export function middleware(request: NextRequest) { } if (request.nextUrl.pathname.includes("confirm")) { - const type = request.nextUrl.searchParams.get("type"); + const queryType = request.nextUrl.searchParams.get("type"); + + const posSeparator = request.nextUrl.pathname.lastIndexOf("/"); + const type = !!posSeparator + ? request.nextUrl.pathname?.slice(posSeparator + 1) + : ""; + requestHeaders.set("x-confirm-type", type); + requestHeaders.set( + "x-confirm-query", + request.nextUrl.searchParams.toString(), + ); + return NextResponse.rewrite( - `${request.nextUrl.origin}/login/confirm/${type}${request.nextUrl.search}`, + `${request.nextUrl.origin}/login/confirm/${queryType}${request.nextUrl.search}`, + { headers: requestHeaders }, ); } @@ -88,5 +100,12 @@ export function middleware(request: NextRequest) { // See "Matching Paths" below to learn more export const config = { - matcher: ["/health", "/", "/not-found", "/consent", "/login", "/confirm"], + matcher: [ + "/health", + "/", + "/not-found", + "/consent", + "/login", + "/confirm/:path*", + ], };