Skip to content

Commit bc78aa2

Browse files
authored
fix(clerk-expo): Accept custom redirect URL for SSO callback (clerk#5102)
1 parent e182055 commit bc78aa2

2 files changed

Lines changed: 30 additions & 5 deletions

File tree

.changeset/flat-horses-battle.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@clerk/clerk-expo': patch
3+
---
4+
5+
Accept custom `redirectURL` for SSO callback via `startSSOFlow`
6+
7+
Usage:
8+
9+
```ts
10+
await startSSOFlow({
11+
strategy: "oauth_google",
12+
redirectUrl: AuthSession.makeRedirectUri({
13+
path: "dashboard"
14+
}),
15+
});
16+
```

packages/expo/src/hooks/useSSO.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as WebBrowser from 'expo-web-browser';
66
import { errorThrower } from '../utils/errors';
77

88
export type StartSSOFlowParams = {
9+
redirectUrl?: string;
910
unsafeMetadata?: SignUpUnsafeMetadata;
1011
} & (
1112
| {
@@ -19,7 +20,7 @@ export type StartSSOFlowParams = {
1920

2021
export type StartSSOFlowReturnType = {
2122
createdSessionId: string | null;
22-
authSessionResult?: WebBrowser.WebBrowserAuthSessionResult;
23+
authSessionResult: WebBrowser.WebBrowserAuthSessionResult | null;
2324
setActive?: SetActive;
2425
signIn?: SignInResource;
2526
signUp?: SignUpResource;
@@ -33,6 +34,7 @@ export function useSSO() {
3334
if (!isSignInLoaded || !isSignUpLoaded) {
3435
return {
3536
createdSessionId: null,
37+
authSessionResult: null,
3638
signIn,
3739
signUp,
3840
setActive,
@@ -47,9 +49,11 @@ export function useSSO() {
4749
* to include the `rotating_token_nonce` on SSO callback
4850
* @ref https://clerk.com/docs/reference/backend-api/tag/Redirect-URLs#operation/CreateRedirectURL
4951
*/
50-
const redirectUrl = AuthSession.makeRedirectUri({
51-
path: 'sso-callback',
52-
});
52+
const redirectUrl =
53+
startSSOFlowParams.redirectUrl ??
54+
AuthSession.makeRedirectUri({
55+
path: 'sso-callback',
56+
});
5357

5458
await signIn.create({
5559
strategy,
@@ -62,13 +66,17 @@ export function useSSO() {
6266
return errorThrower.throw('Missing external verification redirect URL for SSO flow');
6367
}
6468

65-
const authSessionResult = await WebBrowser.openAuthSessionAsync(externalVerificationRedirectURL.toString());
69+
const authSessionResult = await WebBrowser.openAuthSessionAsync(
70+
externalVerificationRedirectURL.toString(),
71+
redirectUrl,
72+
);
6673
if (authSessionResult.type !== 'success' || !authSessionResult.url) {
6774
return {
6875
createdSessionId: null,
6976
setActive,
7077
signIn,
7178
signUp,
79+
authSessionResult,
7280
};
7381
}
7482

@@ -89,6 +97,7 @@ export function useSSO() {
8997
setActive,
9098
signIn,
9199
signUp,
100+
authSessionResult,
92101
};
93102
}
94103

0 commit comments

Comments
 (0)