Skip to content

Commit

Permalink
fix: Handle transfer flow
Browse files Browse the repository at this point in the history
  • Loading branch information
LauraBeatris committed Jan 15, 2025
1 parent 60ce0e3 commit d0f6ed9
Showing 1 changed file with 8 additions and 27 deletions.
35 changes: 8 additions & 27 deletions packages/expo/src/hooks/useSSO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function useSSO(useSSOParams: UseSSOParams) {
const { signIn, setActive, isLoaded: isSignInLoaded } = useSignIn();
const { signUp, isLoaded: isSignUpLoaded } = useSignUp();

async function startFlow(startSSOFlowParams?: StartSSOParams): Promise<StartSSOFlowReturnType> {
async function startFlow(startSSOFlowParams: StartSSOParams): Promise<StartSSOFlowReturnType> {
if (!isSignInLoaded || !isSignUpLoaded) {
return {
createdSessionId: null,
Expand All @@ -49,23 +49,11 @@ export function useSSO(useSSOParams: UseSSOParams) {
path: 'sso-native-callback',
});

if (useSSOParams.strategy === 'enterprise_sso') {
let signInResource = await signIn.create({
identifier: startSSOFlowParams?.identifier as string,
});
console.log('POST:', signInResource);
signInResource = await signIn.prepareFirstFactor({
strategy: useSSOParams.strategy,
redirectUrl,
actionCompleteRedirectUrl: redirectUrl,
});
console.log('PREPARE:', signInResource);
} else {
await signIn.create({
strategy: useSSOParams.strategy,
redirectUrl,
});
}
await signIn.create({
strategy: useSSOParams.strategy,
redirectUrl,
identifier: startSSOFlowParams.identifier,
});

const { externalVerificationRedirectURL } = signIn.firstFactorVerification;
if (!externalVerificationRedirectURL) {
Expand All @@ -88,17 +76,10 @@ export function useSSO(useSSOParams: UseSSOParams) {
};
}

WebBrowser.maybeCompleteAuthSession();

const params = new URL(authSessionResult.url).searchParams;
const rotatingTokenNonce = params.get('rotating_token_nonce');
if (!rotatingTokenNonce) {
return errorThrower.throw(
'Missing rotating_token_nonce in SSO callback. This indicates an API issue - please contact support for assistance.',
);
}

const rotatingTokenNonce = params.get('rotating_token_nonce') ?? '';
await signIn.reload({ rotatingTokenNonce });

if (signIn.firstFactorVerification.status === 'transferable') {
await signUp.create({
transfer: true,
Expand Down

0 comments on commit d0f6ed9

Please sign in to comment.