React Native: AWS amplify requires that I tap `federatedSignIn` twice for google to succeed

Viewed 457

My app is requiring that google oauth (via federatedSignIn) be tapped twice in iOS devices, prior to actually signing the user in.

Process:

  1. Upon the first tap, inapp browser opens up and you select which account you're intending to sign in with. Inapp browser closes and seems like all the rest of my logic is not being hit.
  2. Upon the second tap, the inapp browser re-opens up again for a split second (screen is blank), and then closes and THEN the user is actually signed in.

On the iOS simulator/android, however, it seems like it works as expected. Another strange thing is that it works as expected for oauth'ing in with Apple on all devices.

Wondering if anyone else has run into this issue and if y'all have a suggestion?

Where I instantiate the hub listener:

  useEffect(() => {
    // NOTE: amplify hub listener
    const listener = async (data: any) => {
      switch (data.payload.event) {
        case "signIn":
        case "cognitoHostedUI":
          await signInUser();
          break;
        case "signOut":
          setUser(null);
          break;
        default:
          break;
      }
    };

    Hub.listen("auth", listener);
  }, []);

My google oauth button component:

export function GoogleSignInButton({ title }: GoogleSignInButtonProps) {
  return (
    <SocialIcon
      button
      type="google"
      title={title}
      style={{ padding: 50, marginBottom: 10 }}
      onPress={() =>
        Auth.federatedSignIn({
          provider: "Google" as any,
        }).catch(federatedSignInError => {
          console.log({ federatedSignInError });
          throw new Error(federatedSignInError);
        })
      }
    />
  );
}

I'm also using the react-native-inappbrowser-reborn npm package to have an internal webview when signing in, if that's relevant:

async function urlOpener(url: string, redirectUrl: string) {
  await InAppBrowser.isAvailable();
  const { type, url: newUrl } = (await InAppBrowser.openAuth(url, redirectUrl, {
    showTitle: false,
    enableUrlBarHiding: true,
    enableDefaultShare: false,
    ephemeralWebSession: false,

  })) as RedirectResult;

  if (type === "success") {
    Linking.openURL(newUrl);
  }
}

const appsyncAuthenticationTypeOverride = {
  ...config,
  oauth: {
    ...config.oauth,
    urlOpener,
  },
  aws_appsync_authenticationType: "AWS_IAM",
};

Amplify.configure(appsyncAuthenticationTypeOverride);
1 Answers
Related