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 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/plenty-plants-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-expo': minor
---

Allows passing options such as showInRecents to WebBrowser.openAuthSessionAsync, to prevent android web browser tab closing when navigating away during the SSO login.
11 changes: 7 additions & 4 deletions packages/expo/src/hooks/useSSO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@ import { useSignIn, useSignUp } from '@clerk/clerk-react';
import type { EnterpriseSSOStrategy, OAuthStrategy, SetActive, SignInResource, SignUpResource } from '@clerk/types';
import * as AuthSession from 'expo-auth-session';
import * as WebBrowser from 'expo-web-browser';
import type { AuthSessionOpenOptions } from 'expo-web-browser';

import { errorThrower } from '../utils/errors';

export type StartSSOFlowParams = {
redirectUrl?: string;
unsafeMetadata?: SignUpUnsafeMetadata;
options: AuthSessionOpenOptions;
} & (
| {
| {
strategy: OAuthStrategy;
}
| {
| {
strategy: EnterpriseSSOStrategy;
identifier: string;
}
);
);

export type StartSSOFlowReturnType = {
createdSessionId: string | null;
Expand All @@ -41,7 +43,7 @@ export function useSSO() {
};
}

const { strategy, unsafeMetadata } = startSSOFlowParams ?? {};
const { strategy, unsafeMetadata, options } = startSSOFlowParams ?? {};

/**
* Creates a redirect URL based on the application platform
Expand Down Expand Up @@ -69,6 +71,7 @@ export function useSSO() {
const authSessionResult = await WebBrowser.openAuthSessionAsync(
externalVerificationRedirectURL.toString(),
redirectUrl,
options,
);
if (authSessionResult.type !== 'success' || !authSessionResult.url) {
return {
Expand Down