Search code examples
amazon-web-servicesreact-nativeexpoaws-amplifyaws-amplify-cli

Getting "Unknown: An unknown error has occurred." while trying to signIn using AWS Amplify


I am working on a react native project with expo and I am using AWS amplify for the backend. Signing up a user and confirming the email of said user works as expected but I am getting an Unknown error while trying to sign in.

This is my signIn function Code:

import { signIn, SignInInput } from "aws-amplify/auth";

const onSubmit = async (data: FormData) => {
    setIsLoading(true);
    try {
      const { username, password }: SignInInput = {
        username: data.email,
        password: data.password,
      };
      const { isSignedIn, nextStep } = await signIn({ username, password });
      console.log(isSignedIn, nextStep);
    } catch (e: any) {
      console.log("error signing in", e);
    }
    setIsLoading(false);
  };

Error: error signing in [Unknown: An unknown error has occurred.]


Solution

  • Check your authentication flow perhaps? If this is the case, you'll need to update in your request and in your AWS Cognito App Client.

    Request:

    const { isSignedIn, nextStep } = await signIn({
        username: _data.email,
        password: _data.password,
        options: { authFlowType: "USER_PASSWORD_AUTH" },
      });
    

    App Client: AWS Management Console > Cognito > User Pools > App Integration > (Select your app Client) > (Edit App Client Information) > Add "ALLOW_USER_PASSWORD_AUTH"