Skip to content

Commit 14d21fd

Browse files
authored
fix(supabase): Preserve extra search parameters (#12102)
1 parent 0dd1914 commit 14d21fd

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

.changesets/12102.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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.

packages/auth-providers/supabase/web/src/supabase.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)