react-nativeaws-amplify-sdk-js

React native proper handling of amplify Auth.federatedSignIn


so I am a bit new to react native, I am currently trying to implement Cognito social logins for my application, and the 3rd party sign ins work but the code itself does not wait for the successful login.

I'm sure I'm missing something simplistic.

const socialSignIn = async (provider: string) => {
  const result = await Auth.federatedSignIn({ provider: provider });

  if (result) {
    setIsSignedIn(true);
  }
};

This is the block of code, it opens the native browser and brings up the login page for the given social sign in, sign in works and will redirect back to the app. But the await code already executed, so I am wondering what I should be listening to / checking for that redirect back to the app? I know the sign in works because the next call to federatedSignIn will return credentials

I have seen some people use Hub.listen but I have not had any luck getting that to be called after the redirect back to the app.

Thanks


Solution

  • This part of the Cognito flow being broken was because I missed the part on the documentation where it said to add the DeepLinking for react native. Along with a misunderstanding of how react native runs on device, so the redirect outside the app kills the await sequence.

    it can be found here