From fc65293d987af39297ff502602b189e819437f23 Mon Sep 17 00:00:00 2001 From: gbuomprisco Date: Sat, 15 Jun 2024 21:15:57 +0800 Subject: [PATCH] Update localhost logic in auth-callback service The logic handling localhost in the auth-callback service has been updated. The host is no longer automatically set to the request host; instead, it's only updated if it's currently set to localhost and the request host does not include localhost itself. This change improves handling of different host configurations. --- packages/supabase/src/auth-callback.service.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/supabase/src/auth-callback.service.ts b/packages/supabase/src/auth-callback.service.ts index 1d709e7b1..c9f336d6c 100644 --- a/packages/supabase/src/auth-callback.service.ts +++ b/packages/supabase/src/auth-callback.service.ts @@ -36,18 +36,21 @@ class AuthCallbackService { const url = new URL(request.url); const searchParams = url.searchParams; - // set the host to the request host - // since outside of Vercel it gets set as "localhost" - if (url.host.includes('localhost:')) { - url.host = request.headers.get('host') as string; + const host = request.headers.get('host'); + + // set the host to the request host since outside of Vercel it gets set as "localhost" + if (url.host.includes('localhost:') && !host?.includes('localhost')) { + url.host = host as string; url.port = ''; } const token_hash = searchParams.get('token_hash'); const type = searchParams.get('type') as EmailOtpType | null; const callbackParam = searchParams.get('callback'); - - const next = callbackParam ? new URL(callbackParam).pathname : params.redirectPath; + + const next = callbackParam + ? new URL(callbackParam).pathname + : params.redirectPath; const callbackUrl = callbackParam ? new URL(callbackParam) : null; const inviteToken = callbackUrl?.searchParams.get('invite_token');