File tree Expand file tree Collapse file tree 2 files changed +33
-7
lines changed
packages/auth-providers/supabase/web/src Expand file tree Collapse file tree 2 files changed +33
-7
lines changed Original file line number Diff line number Diff line change 1+ - fix(supabase): Preserve extra search parameters (#12102 ) by @Tobbe
2+
3+ We call the ` restoreAuthState() ` function in the Supabase auth integration when
4+ the user gets redirected back to the app. The problem was that this would
5+ completely wipe out all search parameters, including user-defined ones.
6+
7+ With this PR we only delete the parameters that Supabase manages.
Original file line number Diff line number Diff line change @@ -284,16 +284,35 @@ function createAuthImplementation({
284284 }
285285 }
286286
287- // Modify URL state only if there is a session.
288- // Prevents resetting URL state (like query params) for all other cases.
289- window . history . replaceState (
290- { } ,
291- document . title ,
292- window . location . pathname ,
293- )
287+ // Clean up OAuth callback parameters while preserving other search params
288+ const currentUrl = new URL ( window . location . href )
289+ const authParams = [
290+ 'access_token' ,
291+ 'refresh_token' ,
292+ 'token_type' ,
293+ 'expires_in' ,
294+ 'expires_at' ,
295+ ]
296+
297+ let hasAuthParams = false
298+
299+ // Remove only Supabase auth-related parameters
300+ authParams . forEach ( ( param ) => {
301+ if ( currentUrl . searchParams . has ( param ) ) {
302+ currentUrl . searchParams . delete ( param )
303+ hasAuthParams = true
304+ }
305+ } )
306+
307+ // Only modify URL if we actually removed auth parameters
308+ if ( hasAuthParams ) {
309+ const cleanUrl = currentUrl . pathname + ( currentUrl . search || '' )
310+ window . history . replaceState ( { } , document . title , cleanUrl )
311+ }
294312 } catch ( error ) {
295313 console . error ( error )
296314 }
315+
297316 return
298317 } ,
299318 // This is important, so we can skip fetching getCurrentUser
You can’t perform that action at this time.
0 commit comments