clerk / clerk-expo-starter

Expo starter project using Clerk for authentication
90 stars 19 forks source link

Oauth Signup (React Native/Expo) #19

Open airowe opened 5 months ago

airowe commented 5 months ago

After starting the OAuth flow and not receiving a sessionId back, what should be the next steps for signing up with OAuth in an Expo React Native application?

The docs say (https://clerk.com/docs/quickstarts/expo#o-auth-login) "If you want to add OAuth login flows to your Expo application, Clerk's OAuth hook allows you to handle both sign in and sign up in a single flow."

I'm not sure the next steps to to take if there is no createdSessionId returned in the code below. Users who have yet to sign up and/or have uninstalled and reinstalled our app are not even seeing the Google Popup in this scenario.

const onPress = React.useCallback(async () => {
    try {
      const { createdSessionId, signIn, signUp, setActive } =
        await startOAuthFlow();

      if (createdSessionId) {
        setActive({ session: createdSessionId });
      } else {
        // Use signIn or signUp for next steps such as MFA
      }
    } catch (err) {
      console.error("OAuth error", err);
    }
  }, []);
pArtour commented 4 months ago

Having the same issue. Followed docs steps and get empty createdSessionId. authSessionResult.type is "success".

airowe commented 4 months ago

Having the same issue. Followed docs steps and get empty createdSessionId. authSessionResult.type is "success".

Might be just me, but I finally resolved this by doing Step 4 "Protecting the pages". It appears this step is actually required to get the flow documented in the example working.

octoper commented 3 months ago

Hello @airowe happy to hear that you have resolved your issue.

octoper commented 3 months ago

Hello @pArtour do you manage to fix the issues by following Step 4 as @airowe mentioned?

KennethWrong commented 3 months ago

Any updates on this? I am also facing the exact same issue. Even with the protection it did not work

NiekSulter commented 3 months ago

We are facing the same issue for new users, the createdSessionId is empty, when logging the signIn object the firstFactorVerification key has an error value of 'external_account_not_found'. Looking into this, it doesn't seem vendor specific, both google and microsoft providers give the same error message. @clerk/clerk-expo: 1.0.0-beta.32

luca-trifilio commented 2 months ago

Hi everyone, I'm facing the exact issue explained by @NiekSulter. As a further note, I'm using the same Clerk and Google auth configuration in a Next.js app, and it's working fine, allowing new users to sign in. On Expo, instead:

luca-trifilio commented 2 months ago

Update: I think I managed to solve. I was missing to set a value for the required username field. I forgot to have established it as required in the Clerk dashboard. As far as I can see, in a web app the flow is entirely managed by Clerk, in fact after the first sign-in using a Google account it shows a username field to fill in order to continue with the sign-up process.

On Expo, I had to manage properly this kind of flow.

This is my current solution, feel free to use it or improve it as well:

const { createdSessionId, setActive, signIn, signUp } =
        await selectedAuth();

if (createdSessionId) {
  await setActive!({ session: createdSessionId });
  router.replace("/home");
} else {
  const response = await signUp?.update({
    username: signUp!.emailAddress!.split("@")[0],
  });
  if (response?.status === "complete") {
    await setActive!({ session: signUp!.createdSessionId });
    router.replace("/home");
  }
}

Hope it helps.

jmPramod commented 1 month ago

I am facing same issue , the createdSessionId in console is blank. I tried step4 solution suggested by @airowe. it didn't resolve my issue . any update on this ?


  const { startOAuthFlow } = useOAuth({ strategy: 'oauth_google' });
 const googleAuthSignUp = async () => {
    try {
      const { createdSessionId, signIn, signUp, setActive } =
        await startOAuthFlow();
      console.log('createdSessionId', createdSessionId);

      if (createdSessionId) {
        await setActive!({ session: createdSessionId });
        // router.back();
      }
    } catch (error) {
      console.error('OAuth error', error);
    }
  };
chetryJyoti commented 1 month ago

You should check if you have some required fields in clerk dashboard for eg:email or phone no. or username, just make them optional . This will resolve the issue.

PrateekTewary commented 2 weeks ago

You should check if you have some required fields in clerk dashboard for eg:email or phone no. or username, just make them optional . This will resolve the issue.

@chetryJyoti this worked! I was facing this issue for quite some time and was totally clueless as to what it was being caused by. Clerk team should add some error mentioning required fields were not added.