From bb846f461eefe7a8bdf2c07311ccbd532d16810c Mon Sep 17 00:00:00 2001 From: gbuomprisco Date: Mon, 1 Jul 2024 16:25:34 +0800 Subject: [PATCH] Enhance handling of 'next' path in auth callback This update improves the logic for handling the 'next' path in the auth callback service. Now, it first checks the query parameters for the 'next' path. If it's not found there, it looks into the callback URL --- packages/supabase/src/auth-callback.service.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/supabase/src/auth-callback.service.ts b/packages/supabase/src/auth-callback.service.ts index d0b6e59bc..dec133f88 100644 --- a/packages/supabase/src/auth-callback.service.ts +++ b/packages/supabase/src/auth-callback.service.ts @@ -49,9 +49,24 @@ class AuthCallbackService { const token_hash = searchParams.get('token_hash'); const type = searchParams.get('type') as EmailOtpType | null; const callbackParam = searchParams.get('callback'); + const nextParam = searchParams.get('next'); + let nextPath: string | null = null; const callbackUrl = callbackParam ? new URL(callbackParam) : null; - const nextPath = callbackUrl ? callbackUrl.searchParams.get('next') : null; + + // if we have a next path in the query params, we use that + if (nextParam) { + nextPath = nextParam; + } else { + // if we have a callback url, we check if it has a next path + const callbackNextPath = callbackUrl ? callbackUrl.searchParams.get('next') : null; + + // if we have a next path in the callback url, we use that + if (callbackNextPath) { + nextPath = callbackNextPath; + } + } + const inviteToken = callbackUrl?.searchParams.get('invite_token'); const errorPath = params.errorPath ?? '/auth/callback/error';