Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export async function GET(
request: NextRequest,
{ params }: { params: ManageParams }
) {
const currentUrl = request.nextUrl;
const requestSearchParams = request.nextUrl.searchParams;
const { locale } = params;

Expand Down Expand Up @@ -53,5 +54,12 @@ export async function GET(
console.error(error);
}

redirect(redirectUrl ?? redirectToUrl.href);
let finalRedirectUrl = redirectUrl ?? redirectToUrl.href;
// Avoid redirecting back to this same landing URL
if (finalRedirectUrl === currentUrl.href) {
// Prefer the manage URL instead of looping
finalRedirectUrl = redirectToUrl.href;
}

redirect(finalRedirectUrl);
}
4 changes: 3 additions & 1 deletion apps/payments/next/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export function middleware(request: NextRequest) {
request.nextUrl.pathname,
request.headers.get('accept-language')
);
if (result.redirect) {

// Redirect only if the pathname has changed to avoid an infinite redirect loop
if (result.redirect && result.pathname !== request.nextUrl.pathname) {
return NextResponse.redirect(
new URL(`${result.pathname}${request.nextUrl.search}`, request.url)
);
Expand Down