Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React Native - signIn [Unknown: An unknown error has ocurred.] #12593

Closed
3 tasks done
mtergel opened this issue Nov 20, 2023 · 41 comments
Closed
3 tasks done

React Native - signIn [Unknown: An unknown error has ocurred.] #12593

mtergel opened this issue Nov 20, 2023 · 41 comments
Assignees
Labels
Auth Related to Auth components/category investigating This issue is being investigated pending-maintainer-response Issue is pending a response from the Amplify team. V6 V6 of Amplify JS

Comments

@mtergel
Copy link

mtergel commented Nov 20, 2023

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

Authentication

Amplify Categories

auth

Environment information

# Put output below this line
@aws-amplify/react-native => 1.0.3
aws-amplify => 6.0.3

Describe the bug

getting error [Unknown: An unknown error has ocurred.] only when calling signIn

Expected behavior

signIn to work

Reproduction steps

call signIn

Code Snippet

// Put your code below this line.

Log output

// Put your logs below this line


aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

@mtergel mtergel added the pending-triage Issue is pending triage label Nov 20, 2023
@nadetastic nadetastic added the Auth Related to Auth components/category label Nov 20, 2023
@nadetastic nadetastic self-assigned this Nov 20, 2023
@nadetastic nadetastic added investigating This issue is being investigated and removed pending-triage Issue is pending triage labels Nov 20, 2023
@steve-calverley
Copy link

Im also getting this on the confirmSignIn after a successful challenge response - working fine in v5 and no change to CUSTOM_CHALLENGE
signIn returns the expected Output
confirmSignInOutput {"isSignedIn": false, "nextStep": {"additionalInfo": {"attempts": "1", "attemptsLeft": "2", "maxAttempts": "3", "phone_number": "+61********"}, "signInStep": "CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE"}}
But passing correct challenge will throw Unkown Error

@joaobsantos
Copy link

joaobsantos commented Nov 21, 2023

Hi guys I'm also getting this error, I've installed a fresh expo49 app and only the aws amplify to test it, and I got this error signing in [Unknown: An unknown error has ocurred.]

Also today I've tried the new versions:
"@aws-amplify/react-native": "^1.0.4"
"aws-amplify": "^6.0.4",
"react-native-get-random-values": "1.10.0"

Still the same problem. Thx

@israx
Copy link
Member

israx commented Nov 21, 2023

Hello @mtergel , @joaobsantos . Sorry to hear you are having issues with the signIn API. Just to make sure, what are the actual steps to trigger this error ? . Can you also console log the underlyingError from the AuthError . e.g error.underlyingError ?

@israx
Copy link
Member

israx commented Nov 21, 2023

hello @steve-calverley . Sorry about the issues with the confirmSignIn API. Seems you are getting this error when calling it with the right challenge. Can you also console log the underlyingError from the AuthError ?

@joaobsantos
Copy link

Can you also console log the underlyingException from the AuthError

Hi @israx , heres the log : signing in undefined

Maybe its not iniatializing Amplify.configure?!

@israx
Copy link
Member

israx commented Nov 21, 2023

@joaobsantos can you screenshot the error please ?

@israx
Copy link
Member

israx commented Nov 21, 2023

Something I forgot @joaobsantos , just for testing purposes only. Can you call the signIn API as follows.

await signIn({
	username: 'your_username',
	password: 'your_password',
	options: {
		authFlowType: 'USER_PASSWORD_AUTH',
	},
});

This will change the actual auth flow type. However we recommend using the default flow which is SRP. Let me know if that ends up working please.

@joaobsantos
Copy link

@israx here it is:

image

@israx
Copy link
Member

israx commented Nov 21, 2023

Sorry my mistake. It should be error.underlyingError , apologies.

@joaobsantos
Copy link

joaobsantos commented Nov 21, 2023

Error signing in: [Error: The package '@aws-amplify/react-native' doesn't seem to be linked. Make sure:

  • You rebuilt the app after installing the package
  • You are not using Expo Go

I have "@aws-amplify/react-native": "^1.0.4", installed...

@israx
Copy link
Member

israx commented Nov 21, 2023

can you delete node_modules and package.lock.json ?. Then try to install everything and rebuild the app as suggested above.

@joaobsantos
Copy link

I've already done that, but im using expo with expo go and I follow your docs... I dont have to build a development app... I mean in verwsion 4 everything worked great... Only in 5 and 6 I get this problem. I dont know.

@nadetastic
Copy link
Member

Hi @mtergel can you confirm that you have installed react-native-get-random-values in your project?

@joaobsantos
Copy link

Hi @nadetastic , I can confirm that I have in mine:

"dependencies": {
"@aws-amplify/react-native": "^1.0.4",
"@aws-amplify/rtn-web-browser": "^1.0.4",
"@expo/vector-icons": "^13.0.0",
"@react-native-async-storage/async-storage": "1.18.2",
"@react-native-community/netinfo": "9.3.10",
"@react-navigation/native": "^6.0.2",
"aws-amplify": "^6.0.4",
"expo": "~49.0.20",
"expo-font": "~11.4.0",
"expo-linking": "~5.0.2",
"expo-router": "^2.0.0",
"expo-splash-screen": "~0.20.5",
"expo-status-bar": "~1.6.0",
"expo-system-ui": "~2.4.0",
"expo-web-browser": "~12.3.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-native": "0.72.6",
"react-native-gesture-handler": "~2.12.0",
"react-native-get-random-values": "~1.9.0",
"react-native-safe-area-context": "4.6.3",
"react-native-screens": "~3.22.0",
"react-native-web": "~0.19.6"
},

@steve-calverley
Copy link

steve-calverley commented Nov 21, 2023

hello @steve-calverley . Sorry about the issues with the confirmSignIn API. Seems you are getting this error when calling it with the right challenge. Can you also console log the underlyingError from the AuthError ?

@israx Console Log - [TypeError: Cannot read property 'setTokens' of undefined]

Upgrade to 6.0.4 and removed lock etc
"react-native-get-random-values": "^1.9.0", installed

@israx
Copy link
Member

israx commented Nov 21, 2023

@steve-calverley what are your dependencies ? Wondering if @react-native-async-storage/async-storage is installed?

@steve-calverley
Copy link

steve-calverley commented Nov 21, 2023

@israx Deps

"dependencies": {
"@aws-amplify/react-native": "^1.0.3",
"@aws-amplify/rtn-push-notification": "^1.2.0",
"@faker-js/faker": "^8.0.2",
"@gorhom/bottom-sheet": "^4.4.7",
"@hookform/resolvers": "^3.1.1",
"@react-native-async-storage/async-storage": "^1.19.5",
"@react-native-community/blur": "^4.3.2",
"@react-native-community/checkbox": "^0.5.16",
"@react-native-community/netinfo": "^11.1.0",
"@react-native-picker/picker": "^2.4.10",
"@react-native-segmented-control/segmented-control": "^2.4.2",
"@react-navigation/bottom-tabs": "^6.5.7",
"@react-navigation/drawer": "^6.6.3",
"@react-navigation/native": "^6.1.6",
"@react-navigation/native-stack": "^6.9.12",
"@shopify/flash-list": "^1.6.1",
"add": "^2.0.6",
"appcenter": "^4.4.5",
"appcenter-analytics": "^4.4.5",
"appcenter-crashes": "^4.4.5",
"aws-amplify": "^6.0.4",
"babel-preset-env": "^1.7.0",
"babel-preset-react-native": "^4.0.1",
"core-js": "^3.31.0",
"emoji-regex": "^10.2.1",
"emoji-utils": "^1.0.1",
"exponential-backoff": "^3.1.1",
"i18next": "^23.2.3",
"immer": "9.0.6",
"intl-pluralrules": "^2.0.1",
"libphonenumber-js": "^1.10.44",
"lodash": "^4.17.21",
"lottie-react-native": "^5.1.6",
"luxon": "^3.4.3",
"mitt": "^3.0.1",
"moment": "^2.29.4",
"moment-timezone": "^0.5.43",
"nativewind": "^2.0.11",
"patch-package": "^7.0.0",
"postinstall-postinstall": "^2.1.0",
"react": "18.2.0",
"react-hook-form": "^7.45.0",
"react-i18next": "^13.0.1",
"react-native": "0.72.4",
"react-native-avoid-softinput": "^4.0.0",
"react-native-base64": "^0.2.1",
"react-native-bootsplash": "^5.0.2",
"react-native-camera": "^4.2.1",
"react-native-compressor": "^1.6.1",
"react-native-config": "^1.5.1",
"react-native-confirmation-code-field": "^7.3.1",
"react-native-contacts": "^7.0.7",
"react-native-date-picker": "^4.2.13",
"react-native-device-info": "^10.8.0",
"react-native-fast-image": "^8.6.3",
"react-native-flipper": "^0.212.0",
"react-native-gesture-handler": "^2.12.0",
"react-native-get-random-values": "^1.9.0",
"react-native-gifted-chat": "^2.4.0",
"react-native-haptic-feedback": "^2.2.0",
"react-native-image-picker": "^5.6.0",
"react-native-inappbrowser-reborn": "^3.7.0",
"react-native-keyboard-controller": "^1.5.6",
"react-native-linear-gradient": "^2.6.2",
"react-native-localize": "^3.0.2",
"react-native-markdown-display": "^7.0.0-alpha.2",
"react-native-mask-input": "^1.2.3",
"react-native-mmkv": "^2.9.0",
"react-native-pager-view": "^5.4.9",
"react-native-reanimated": "3.3.0",
"react-native-reanimated-carousel": "^3.4.0",
"react-native-safe-area-context": "^4.5.3",
"react-native-screens": "^3.21.0",
"react-native-section-list-get-item-layout": "^2.2.3",
"react-native-snap-carousel": "^3.9.1",
"react-native-sqlite-storage": "^6.0.1",
"react-native-svg": "^13.9.0",
"react-native-tracking-transparency": "^0.1.2",
"react-native-url-polyfill": "^2.0.0",
"react-native-webview": "^13.2.2",
"react-phone-number-input": "^3.2.25",
"rive-react-native": "^4.1.2",
"uuid": "^9.0.0",
"yarn": "^1.22.19",
"yup": "^1.2.0",
"yup-phone-lite": "^2.0.1",
"zustand": "^4.4.4"
},

@elorzafe
Copy link
Contributor

@steve-calverley

Can you shared a redacted example of how you are importing, configuring and calling the APIs?

@elorzafe
Copy link
Contributor

@joaobsantos

On the code that you shared I think the signIn invocation should have the options: { authFlowType: '...' } not handleSignIn. Also can you share how you are importing and configuring (redacted) the library?

@elorzafe
Copy link
Contributor

@mtergel can you share your app package.json?

@steve-calverley
Copy link

steve-calverley commented Nov 21, 2023

@steve-calverley

Can you shared a redacted example of how you are importing, configuring and calling the APIs?

@elorzafe two functions we use - very rough for testing this issue

 const signIn = async (username: string) => {
    try {
      const signInResult = await AWSSignIn({
        username,
        options: {
          authFlowType: 'CUSTOM_WITHOUT_SRP',
        },
      });

      console.log('signInResult', signInResult);
      const {isSignedIn, nextStep} = signInResult;

      if (isSignedIn) {
        return initSignIn();
      }

      switch (nextStep.signInStep) {
        case 'CONFIRM_SIGN_IN_WITH_CUSTOM_CHALLENGE':
          break;
        case 'CONFIRM_SIGN_IN_WITH_NEW_PASSWORD_REQUIRED':
          // return signInResult;
          break;
        case 'RESET_PASSWORD':
          break;
        default:
          console.log(nextStep.signInStep);
          throw new Error('Not a Sign In Event we handle');
      }
    } catch (error: unknown) {
      console.log('ERROR::useCognitoUser::signIn:: ', error);
      throw error;
    }
  };

  const sendCustomChallengeAnswer = async (
    answer: string,
  ): Promise<AuthUser | any> => {
    let user;
    try {
      console.log('answer', answer);

      const confirmSignInOutput = await AWSConfirmSignIn({
        challengeResponse: answer,
      });
      console.log('confirmSignInOutput', confirmSignInOutput);
      if (!confirmSignInOutput.isSignedIn) {
        throw new Error('Incorrect Answer. Please try again');
      }
      user = await getCurrentUser();
      console.log('user', user);

      return user;
    } catch (error: unknown) {
      if (!user) {
        console.log(
          'ERROR::useCognitoUser::sendCustomChallengeAnswer:: ',
          error,
        );
        throw new Error('Unable to sign in');
      }
    }
  };

First function is called on screen that obtains phone number -> move to send screen to enter answer -> 2nd function is called.

Config

import amplifyconfig from './src/amplifyconfiguration.json';
Amplify.configure(amplifyconfig);

@mtergel
Copy link
Author

mtergel commented Nov 22, 2023

Thanks guys, we were using nx monorepo, it seemed we need to import react-native-get-random-values to the package.json for our app.

"aws-amplify": "*",
"@react-native-async-storage/async-storage": "*",
"@aws-amplify/react-native": "*",
"react-native-get-random-values": "*"

@mtergel mtergel closed this as completed Nov 22, 2023
@steve-calverley
Copy link

@elorzafe Should I open a new ticket for my issue. Have just upgrade packages
"aws-amplify": "",
"@react-native-async-storage/async-storage": "
",
"@aws-amplify/react-native": "",
"react-native-get-random-values": "
"
and still the same error
ERROR::useCognitoUser::sendCustomChallengeAnswer:: [TypeError: Cannot read property 'setTokens' of undefined]

@joaobsantos
Copy link

joaobsantos commented Nov 22, 2023

@joaobsantos

On the code that you shared I think the signIn invocation should have the options: { authFlowType: '...' } not handleSignIn. Also can you share how you are importing and configuring (redacted) the library?

@elorzafe sorry, you are right, and now it works...
Maybe improve the docs to have the authFlowType: "USER_PASSWORD_AUTH"
https://docs.amplify.aws/react-native/build-a-backend/auth/enable-sign-up/#sign-in

Thx for your time to help me I really apreciate and keep up the good work.

async function handleSignIn({ username, password }: SignInInput) {
    try {
      const user = await signIn({
        username,
        password,
        options: {
          authFlowType: "USER_PASSWORD_AUTH",
        },
      });
      console.log("user", user);
    } catch (error) {
      //@ts-ignore
      console.log("Error signing in:", error.underlyingError);
    }
  } 
  
  
  

@joaobsantos
Copy link

joaobsantos commented Nov 22, 2023

Hi @elorzafe sorry to bother you again, in my clean expo49 it works but then when I do the same thing in my monorepo I get this error right on openning the app (app doesnt work):

ERROR Error: The package '@aws-amplify/react-native' doesn't seem to be linked. Make sure:

  • You rebuilt the app after installing the package
  • You are not using Expo Go
    , js engine: hermes
    ERROR Invariant Violation: "main" has not been registered. This can happen if:
  • Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
  • A module failed to load due to an error and AppRegistry.registerComponent wasn't called., js engine: hermes

I have "@aws-amplify/react-native": "^1.0.4", installed.

If I go to the version that I had before, "aws-amplify": "4.3.43" it works fine...

@israx
Copy link
Member

israx commented Nov 22, 2023

@steve-calverley please do open a new issue so we can keep track of the confirmSignIn issue.

@israx
Copy link
Member

israx commented Nov 22, 2023

@joaobsantos Amplify JS currently doesn't support Expo Go as we are now requiring the use of more native modules to leverage native functionality. Is it possible for you to use the RN CLI instead ? And if you don't mind, can you open an issue with us ? So we can keep track of this issue too.

@joaobsantos
Copy link

@israx but in a clean expo49 project with expo go, works.
I only get that error when I try in a monorepo...

@elorzafe
Copy link
Contributor

@steve-calverley

feel free to open a new issue but I am still not sure why setTokens is failing, I wonder if there is something related to async storage configuration. Are you running the App on iOS, or Android?

@elorzafe
Copy link
Contributor

@joaobsantos happy to help!

We have that setting explained on Switch Authentication Flows docs

Let me know if that clarifies your concerns!

@steve-calverley
Copy link

@steve-calverley

feel free to open a new issue but I am still not sure why setTokens is failing, I wonder if there is something related to async storage configuration. Are you running the App on iOS, or Android?

@elorzafe Running on both iOS and Android emulators. Let me look into Async Config before opening new issue

@joaobsantos
Copy link

Hi @elorzafe , After you pointed me out I went to that link and understood what was happening.

In my opinion the documentation example in signIn should have a reference to that and this code in the example:

options: {
     authFlowType: "USER_PASSWORD_AUTH",
},

@nadetastic nadetastic added the V6 V6 of Amplify JS label Jan 23, 2024
@bertoninicolas
Copy link

bertoninicolas commented Apr 6, 2024

I'm having the same problem after testing some tips proposed here.

"An unknown error has occurred" at the time of login, with account creation and email verification carried out successfully.

import { StatusBar } from 'expo-status-bar';
import RootNavigator from './src/navigation';

import { NavigationContainer } from '@react-navigation/native';
import { Amplify } from 'aws-amplify';
import {  withAuthenticator } from '@aws-amplify/ui-react-native';
import awsExports  from './src/aws-exports';

Amplify.configure(awsExports);

function App() {
  return (
    <NavigationContainer>
      <RootNavigator />

      <StatusBar style="light" />
    </NavigationContainer>
  );
};

export default withAuthenticator(App);

Captura de tela 2024-04-06 162224

I tried using expo go on my iPhone, I used expo go on an android emulator, and none of them work

@nyook941
Copy link

Were you able to figure this out? I have the same issue.

@joaobsantos
Copy link

I still use v5.2.2, it was faster then dealing with this...

@melissacskn
Copy link

I am having the same "an unknown error occurred" on my expo react native app. Does anyone have any suggestions?

@AnirudhHosur
Copy link

Yes, same here I also get this error. @bertoninicolas, I guess even you're developing a food delivery app by following the 5 hours playlist on YT?

@MichelBahl
Copy link

MichelBahl commented May 17, 2024

Docs say you cannot use Expo Go
Bildschirmfoto 2024-05-17 um 16 49 38

Unfortunately you have to:

  1. npx expo prebuild
  2. And use npx expo run:ios instead of npx expo start

In my opinion Expo Go should be supported, there is no reason why native code is necessary, at least the error message should be easier to understand

@raihanNoman
Copy link

I had the same problem

Unknown: An unknown error has occurred.

at assertServiceError (http://localhost:8081/node_modules/expo-router/entry.bundle?platform=web&dev=true&hot=false&transform.routerRoot=app:138951:13)

at signInWithSRP (http://localhost:8081/node_modules/expo-router/entry.bundle?platform=web&dev=true&hot=false&transform.routerRoot=app:144386:7)

at async eval (http://localhost:8081/app/_layout.bundle//&platform=web&hot=false&transform.routerRoot=app&dev=true&minify=false&modulesOnly=true&runModule=false&shallow=true:77:23)`

I tried everything from updating packages, creating new development builds, creating entirely new amplify projects.
Here is what I found:

The problem started when I did amplify update api and did a push
I noticed amplify showing update to my api (REST) as well as auth (I didn't make any explicit changes to my auth)

Then I checked into api gateway, and lo and behold, my Cognito authorizers were missing!
So I had to reset that.....I digress...btw dont forget to hit deploy

Back in my app, I tried signing in

const signInRes = await signIn({
      username: "[email protected]",
      password: "PassWord123",
 });

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

I tried adding options

 const signInRes = await signIn({
        username: "[email protected]",
        password: "Aunto1044",
        options: {
            authFlowType: "USER_AUTH", // 'USER_PASSWORD_AUTH'
       },
 });

Error: [InvalidParameterException: USER_AUTH flow not enabled for this client]
Error: [InvalidParameterException: USER_PASSWORD_AUTH flow not enabled for this client]

I thought my user might have had a problem, so i deleted that user and signed up, confirm sign up (everything in the simple/normal way) and signup flow works! But again signing in produces the same error

Like @joaobsantos and @elorzafe suggested, I read up on the docs:
https://docs.amplify.aws/gen1/react-native/build-a-backend/auth/switch-auth/#user_password_auth-flow

I headed to Cognito and
Screenshot 2024-12-21 at 9 23 10 AM
--click App Client

and for both of these options:
Screenshot 2024-12-21 at 9 24 00 AM

You must enable Username and Password
Screenshot 2024-12-21 at 9 26 02 AM

If you dont see it included, click Edit and check the box:
Screenshot 2024-12-21 at 9 29 14 AM

Then save changes
Try signing in through your app and it works!

Future notes:

  • Its not an issue with packages or package versions
  • Its simply sometimes amplify resets itself to defaults (for reasons unknown to mortal men) and you gotta do a through check in the setting of all your services.
  • if you make changes from amplify cli and push, and you see unrelated changes like amplify automatically saying its gonna update auth and api, double check cognito and api gateway to ensure everything is as expected.

@github-actions github-actions bot added the pending-maintainer-response Issue is pending a response from the Amplify team. label Dec 21, 2024
@MuhammadAflah
Copy link

@raihanNoman Thanks for the updated explanation, it works. 👍

@AnirudhHosur
Copy link

As I wasn't able to make it work with Amplify. I used GCP Firebase instead and it was way easier. Firebase also provides hosting. You can find my repository. I created a 3 app food delivery module (Uber eats replica) following a YT series. @MuhammadAflah

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auth Related to Auth components/category investigating This issue is being investigated pending-maintainer-response Issue is pending a response from the Amplify team. V6 V6 of Amplify JS
Projects
None yet
Development

No branches or pull requests