Skip to content

fix(clerk-expo): prevent android web browser tab closing in backgroun… #6050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

FabianUntermoser
Copy link

@FabianUntermoser FabianUntermoser commented Jun 2, 2025

Description

Allows passing showInRecents option to WebBrowser.openAuthSessionAsync, which prevents the web browser tab closing when navigating away during the SSO login on android.

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • New Features
    • Added support for passing additional options, such as keeping the Android web browser tab open during SSO login, to the authentication session.

…d during SSO auth

allow passing showInRecents option for WebBrowser.openAuthSessionAsync
Copy link

changeset-bot bot commented Jun 2, 2025

🦋 Changeset detected

Latest commit: 180c0e5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clerk/clerk-expo Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Jun 2, 2025

@FabianUntermoser is attempting to deploy a commit to the Clerk Production Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Jul 12, 2025

📝 Walkthrough

Walkthrough

A new changeset file was added to document a minor version update for the @clerk/clerk-expo package. The update introduces support for passing additional options, specifically the showInRecents property, to the WebBrowser.openAuthSessionAsync method. The StartSSOFlowParams type was modified to make the options property of type AuthSessionOpenOptions optional, and the startSSOFlow function was updated to accept and utilize these optional options when initiating the authentication session. No other logic or control flow was changed.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a733915 and 180c0e5.

📒 Files selected for processing (1)
  • packages/expo/src/hooks/useSSO.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/expo/src/hooks/useSSO.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🔭 Outside diff range comments (1)
packages/expo/src/hooks/useSSO.ts (1)

35-105: Add tests to cover the new options parameter functionality.

No tests were added to cover the new options parameter. Consider adding tests to verify that:

  1. Options are properly passed to WebBrowser.openAuthSessionAsync
  2. The SSO flow works correctly with different option configurations
  3. Backward compatibility is maintained (if options become optional)

Would you like me to help generate test cases for this functionality?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ab31ae8 and a733915.

📒 Files selected for processing (2)
  • .changeset/plenty-plants-clap.md (1 hunks)
  • packages/expo/src/hooks/useSSO.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{js,jsx,ts,tsx}

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/development.mdc
packages/**/*.ts

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/development.mdc
packages/**/*.{ts,tsx,d.ts}

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/development.mdc
**/*.{ts,tsx}

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • .cursor/rules/development.mdc
  • .cursor/rules/typescript.mdc
**/*.ts

Instructions used from:

Sources:
⚙️ CodeRabbit Configuration File

**/*

Instructions used from:

Sources:
⚙️ CodeRabbit Configuration File

🧠 Learnings (3)
📓 Common learnings
Learnt from: LauraBeatris
PR: clerk/javascript#6117
File: packages/clerk-js/src/ui/components/SessionTasks/index.tsx:64-83
Timestamp: 2025-06-18T16:33:36.764Z
Learning: In SessionTasks component at packages/clerk-js/src/ui/components/SessionTasks/index.tsx, the useEffect that checks for pending tasks should only run on mount (not react to currentTask/status changes) to handle browser back navigation edge cases without interfering with normal task completion flow managed by nextTask().
Learnt from: dstaley
PR: clerk/javascript#6116
File: .changeset/tangy-garlics-say.md:1-2
Timestamp: 2025-06-13T16:09:53.061Z
Learning: In the Clerk JavaScript repository, contributors create intentionally empty changeset files (containing only the YAML delimiters) when a PR touches only non-published parts of the codebase (e.g., sandbox assets). This signals that no package release is required, so such changesets should not be flagged as missing content.
Learnt from: dstaley
PR: clerk/javascript#6100
File: packages/clerk-js/src/ui/components/OAuthConsent/OAuthConsent.tsx:121-124
Timestamp: 2025-06-16T17:08:58.414Z
Learning: The @clerk/clerk-js package only supports browsers released in the last two years (since May 8, 2023), so modern CSS features like color-mix() are fully supported across all target browsers without requiring fallbacks.
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/development.mdc:0-0
Timestamp: 2025-06-30T10:29:42.997Z
Learning: Update documentation for API changes
Learnt from: panteliselef
PR: clerk/javascript#6285
File: packages/types/src/commerce.ts:1305-1305
Timestamp: 2025-07-11T18:08:14.618Z
Learning: In the Clerk JavaScript repository, when there's a conflict between naming consistency (camelCase) and avoiding breaking changes, the team prioritizes maintaining backward compatibility over enforcing naming conventions, even for experimental APIs.
.changeset/plenty-plants-clap.md (4)
Learnt from: dstaley
PR: clerk/javascript#6116
File: .changeset/tangy-garlics-say.md:1-2
Timestamp: 2025-06-13T16:09:53.061Z
Learning: In the Clerk JavaScript repository, contributors create intentionally empty changeset files (containing only the YAML delimiters) when a PR touches only non-published parts of the codebase (e.g., sandbox assets). This signals that no package release is required, so such changesets should not be flagged as missing content.
Learnt from: jacekradko
PR: clerk/javascript#5905
File: .changeset/six-ears-wash.md:1-3
Timestamp: 2025-06-26T03:27:05.535Z
Learning: In the Clerk JavaScript repository, changeset headers support single quotes syntax (e.g., '@clerk/backend': minor) and work fine with their current changesets integration, so there's no need to change them to double quotes.
Learnt from: panteliselef
PR: clerk/javascript#6285
File: packages/types/src/commerce.ts:1305-1305
Timestamp: 2025-07-11T18:08:14.618Z
Learning: In the Clerk JavaScript repository, when there's a conflict between naming consistency (camelCase) and avoiding breaking changes, the team prioritizes maintaining backward compatibility over enforcing naming conventions, even for experimental APIs.
Learnt from: dstaley
PR: clerk/javascript#6100
File: packages/clerk-js/src/ui/components/OAuthConsent/OAuthConsent.tsx:121-124
Timestamp: 2025-06-16T17:08:58.414Z
Learning: The @clerk/clerk-js package only supports browsers released in the last two years (since May 8, 2023), so modern CSS features like color-mix() are fully supported across all target browsers without requiring fallbacks.
packages/expo/src/hooks/useSSO.ts (2)
Learnt from: CR
PR: clerk/javascript#0
File: .cursor/rules/react.mdc:0-0
Timestamp: 2025-06-30T10:32:37.848Z
Learning: Applies to **/*.tsx : Use proper type definitions for props and state
Learnt from: wobsoriano
PR: clerk/javascript#6123
File: packages/nextjs/src/server/__tests__/getAuthDataFromRequest.test.ts:63-75
Timestamp: 2025-06-16T01:27:54.563Z
Learning: In packages/nextjs/src/server/data/getAuthDataFromRequest.ts, the tokenType behavior on mismatch is intentionally different between array and single acceptsToken values: when acceptsToken is an array and the token type doesn't match any in the array, tokenType returns null; when acceptsToken is a single value and the token type doesn't match, tokenType returns the requested single value. This design aligns with developer intent and provides a more ergonomic API for common use cases.
🧬 Code Graph Analysis (1)
packages/expo/src/hooks/useSSO.ts (1)
packages/types/src/strategies.ts (1)
  • EnterpriseSSOStrategy (16-16)
🔇 Additional comments (3)
packages/expo/src/hooks/useSSO.ts (2)

5-5: Import statement looks good.

The import of AuthSessionOpenOptions from expo-web-browser is correctly typed and necessary for the new functionality.


46-46: Parameter extraction is implemented correctly.

The destructuring of options from startSSOFlowParams is properly implemented.

.changeset/plenty-plants-clap.md (1)

1-6: Changeset properly documents the feature addition.

The changeset correctly uses a minor version bump for the new functionality and provides a clear description of the change. The documentation accurately reflects the purpose of allowing options like showInRecents to prevent Android web browser tab closure during SSO login.

@@ -69,6 +71,7 @@ export function useSSO() {
const authSessionResult = await WebBrowser.openAuthSessionAsync(
externalVerificationRedirectURL.toString(),
redirectUrl,
options,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify authentication flow security implications.

The change to pass custom options to WebBrowser.openAuthSessionAsync modifies authentication behavior and could have security implications. Please ensure the showInRecents option and other potential options don't introduce security vulnerabilities.

@clerk/security


🏁 Script executed:

#!/bin/bash
# Locate the hook file
file=$(fd useSSO.ts)
echo "Found file: $file"
echo "---- Lines 60-100 of useSSO.ts ----"
sed -n '60,100p' "$file"
echo
echo "---- openAuthSessionAsync usage ----"
rg "openAuthSessionAsync" -A3 -B3 "$file"
echo
echo "---- Any occurrences of showInRecents in repo ----"
rg "showInRecents" -A2 -B2

Length of output: 2137


🏁 Script executed:

#!/bin/bash
# Display the hook signature and locate the `options` parameter definition
echo "---- Top of useSSO.ts (lines 1-80) ----"
sed -n '1,80p' packages/expo/src/hooks/useSSO.ts
echo
echo "---- All references to 'options' in useSSO.ts ----"
rg -n "options" packages/expo/src/hooks/useSSO.ts

Length of output: 3050


Enforce secure use of openAuthSessionAsync options

The options object from startSSOFlowParams is passed straight into
WebBrowser.openAuthSessionAsync(...), allowing consumers to override critical flags (e.g. showInRecents, preferEphemeralSession) that impact session security. Please address the following before merging:

• packages/expo/src/hooks/useSSO.ts:74
– Merge user-provided options with a secure baseline, for example:
ts const secureDefaults: AuthSessionOpenOptions = { preferEphemeralSession: true, // …other secure defaults }; const authSessionResult = await WebBrowser.openAuthSessionAsync( externalVerificationRedirectURL.toString(), redirectUrl, { ...secureDefaults, ...options } );
• Validate or whitelist which AuthSessionOpenOptions keys are permitted to prevent unintended behavior (e.g. disallow hiding in recents for sensitive flows).
• Add JSDoc on StartSSOFlowParams.options detailing recommended and discouraged flags.

@clerk/security

🤖 Prompt for AI Agents
In packages/expo/src/hooks/useSSO.ts at line 74, the options object passed to
WebBrowser.openAuthSessionAsync is directly from startSSOFlowParams, which can
override critical security flags. To fix this, define a secureDefaults object
with safe default flags like preferEphemeralSession set to true, then merge user
options into it using spread syntax so secureDefaults take precedence.
Additionally, implement validation or a whitelist to allow only safe
AuthSessionOpenOptions keys, preventing overrides of sensitive flags like
showInRecents. Finally, add JSDoc comments on StartSSOFlowParams.options to
document recommended and discouraged flags for clarity and security guidance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy