fix(rn): avoid safari popup block on web sign-in#63
Open
simeng-li wants to merge 1 commit into
Open
Conversation
On web, the auth popup was opened only after super.signIn awaited OIDC config, PKCE and storage, so the click's user activation was gone and Safari/Firefox blocked it. Pre-open a named blank window synchronously on click and reuse it by name for the auth session, which browsers treat as a navigation rather than a new popup. Native is unaffected. A disableWebPopupWorkaround config flag lets developers opt out and fall back to opening the window directly.
There was a problem hiding this comment.
Pull request overview
This PR fixes Safari/Firefox popup blocking during web sign-in by ensuring the auth window is opened while the user activation from the click is still valid, then reusing that same named window for the actual OIDC authorization navigation.
Changes:
- Pre-opens a named window on web at the start of
LogtoClient.signIn()and reuses it viawindowNameinopenAuthSessionAsync. - Adds a
disableWebPopupWorkaroundconfig flag (defaultfalse) to opt out of the pre-open behavior. - Adds unit tests covering web ordering, native no-op behavior, opt-out behavior, and failure-path cleanup.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/rn/src/client.ts | Adds the web pre-open + named-window reuse workaround, plus an opt-out config flag. |
| packages/rn/src/client.test.ts | Adds Vitest coverage for the popup workaround ordering, platform gating, opt-out, and cleanup behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #45.
On web,
signInopens the authorization window viaWebBrowser.openAuthSessionAsync(→window.open), but only aftersuper.signInawaits OIDC discovery, PKCE, and storage. By then the click's user activation is gone, so Safari and Firefox block it as a popup (Chrome/Edge are lenient, which is why it only reproduced in Safari).What changed
packages/rn/src/client.ts: on web, pre-open a named blank window (WebBrowser.openBrowserAsync('', { windowName: 'logtoAuth' })) synchronously at the start ofsignIn, while the user activation is still alive.openAuthSessionAsyncis then called with the samewindowName, so the browser reuses the existing window as a navigation rather than a blocked new popup. Atry/catchcloses the blank window if sign-in fails before the auth window opens.disableWebPopupWorkaroundconfig flag (defaultfalse) so developers can opt out and fall back to opening the window directly.packages/rn/src/client.test.ts: unit tests for the ordering invariant (pre-open before auth session), native no-op, the opt-out flag, and the failure-path window cleanup.Expected result
about:blankflash before redirect (the standard sync-open-then-navigate popup pattern). Worst case equals current behavior.Platform.OS === 'web', andwindowNameis a web-onlyexpo-web-browseroption (@platform web) that the native auth session ignores.Reviewer notes
signIn(not thenavigateadapter) —navigateruns aftersuper.signIn's async work, i.e. after the gesture is already lost.Testing
Unit tests
Checklist
.changeset