feat: webapp URL based redirects in middleware for external LB integrations (#2151)

Co-authored-by: Matti Nannt <mail@matthiasnannt.com>
This commit is contained in:
Shubham Palriwala
2024-03-02 16:30:20 +05:30
committed by GitHub
parent 56f6dbe9a6
commit ee053e6642
+2 -5
View File
@@ -23,11 +23,8 @@ export async function middleware(request: NextRequest) {
const token = await getToken({ req: request });
if (isWebAppRoute(request.nextUrl.pathname) && !token) {
const loginUrl = new URL(
`/auth/login?callbackUrl=${encodeURIComponent(request.nextUrl.toString())}`,
WEBAPP_URL
);
return NextResponse.redirect(loginUrl.href);
const loginUrl = `${WEBAPP_URL}/auth/login?callbackUrl=${encodeURIComponent(WEBAPP_URL + request.nextUrl.pathname + request.nextUrl.search)}`;
return NextResponse.redirect(loginUrl);
}
const callbackUrl = request.nextUrl.searchParams.get("callbackUrl");