Auth.signIn() promise takes more than 30 seconds to resolve on Android
Describe the bug Auth.signIn() promise can take more than 30 seconds to resolve on Android. On iOS and Web we could not reproduce the bug. It happens when we start the app and we click "Login" for the first time. It doesn't always happen, we have to try a few times to reproduce it.
To Reproduce Steps to reproduce the behavior:
- Close all apps on device.
- Start React Native app using npx react-native run-android
- Click on "Login"
- See console to see how many miliseconds it took to complete the authentication.
Expected behavior It should always be complete under 3 seconds as it happens on the other platforms.
Code Snippet
App.tsx :
import React from "react"; import { StyleSheet, Text, View, TouchableOpacity } from "react-native"; import Amplify, { Auth } from "aws-amplify"; import {awsmobileDev} from './aws-exports' Amplify.configure(awsmobileDev);
export default class App extends React.Component<{}, {}> { render() { return ( <View style={styles.container}> <TouchableOpacity style={{ height: 50, width: 200 }} onPress={async () => { console.log("Signing in..."); const timeStart = new Date().getTime(); await Auth.signIn("username", "password"); const timeEnd = new Date().getTime(); console.log("Sign in successfull. ", timeEnd - timeStart); }} > <Text>Login</Text> </TouchableOpacity> </View> ); } }
const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#fff", alignItems: "center", justifyContent: "center", }, });
Screenshots
Here for example, it lasted 128 seconds to login!
What is Configured? If applicable, please provide what is configured for Amplify CLI:
- Which steps did you follow via Amplify CLI when configuring your resources.
- Which resources do you have configured?
- If applicable, please provide your
aws-exportsfile:
const awsmobile = { aws_project_region: "eu-central-1", aws_cognito_identity_pool_id: "eu-central-1:xxx", aws_cognito_region: "eu-central-1", aws_user_pools_id: "eu-central-1_xxx", aws_user_pools_web_client_id: "xxx", oauth: {}, aws_appsync_graphqlEndpoint: "https://xxx.appsync-api.eu-central-1.amazonaws.com/graphql", aws_appsync_region: "eu-central-1", aws_appsync_authenticationType: "AMAZON_COGNITO_USER_POOLS", aws_cloud_logic_custom: [ { name: "xxx", endpoint: "https://xxx.execute-api.eu-central-1.amazonaws.com/dev", region: "eu-central-1", }, ], aws_mobile_analytics_app_id: "xxx", aws_mobile_analytics_app_region: "eu-central-1", aws_user_files_s3_bucket: "xxx-dev", aws_user_files_s3_bucket_region: "eu-central-1", - If applicable, please provide your
}; };
**Smartphone (please complete the following information):**
- Device: We can see it in all kinds of Android Devices
@jfaq89 I see that you're testing with a development React Native build. Could you also test with a production build on a physical device and verify that you're seeing the same behavior?
Also, what version of aws-amplify are you using?
@jfaq89 I see that you're testing with a development React Native build. Could you also test with a production build on a physical device and verify that you're seeing the same behavior?
Also, what version of
aws-amplifyare you using?
Hi. We already saw the error in production. Many people from my team have tested using different physical devices and everyone managed to reproduce the error.
We tested using the latest version of AWS-amplify.
We're still blocked. The error was seen using version 3.0.9
Any idea how we can fix this?
@jfaq89 A couple of questions/comments:
- What version of React Native are you using?
- What other Amplify categories are you using in your app?
- Could you try reproducing this behavior with a brand new basic app and share it here?
I've got a simple auth app for testing, but I haven't been able to duplicate the issue you're seeing after trying numerous times on an Android device.
@jfaq89 A couple of questions/comments:
- What version of React Native are you using?
- What other Amplify categories are you using in your app?
- Could you try reproducing this behavior with a brand new basic app and share it here?
I've got a simple auth app for testing, but I haven't been able to duplicate the issue you're seeing after trying numerous times on an Android device.
- React Native version : 0.61.5
- On this brand new basic app that I made to debug this problem, I only use "Auth".
- Here is the code: (the awsmobileDev config is the one I posted above)
import React from "react";
import { StyleSheet, Text, View, TouchableOpacity } from "react-native";
import { Auth } from "aws-amplify";
import {awsmobileDev} from './aws-exports'
Auth.configure(awsmobileDev);
// Amplify.Logger.LOG_LEVEL = "DEBUG";
export default class App extends React.Component<{}, {}> {
render() {
return (
<View style={styles.container}>
<TouchableOpacity
style={{ height: 50, width: 200 }}
onPress={async () => {
console.log("Signing in...");
const timeStart = new Date().getTime();
await Auth.signIn("[email protected]", "password");
const timeEnd = new Date().getTime();
console.log("Sign in successfull. ", timeEnd - timeStart);
}}
>
<Text style={{ textAlign: "center" }}>Login</Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
});
It is not very easy to reproduce the error. You have to try a few times. It is easier to reproduce on a physical device than on a simulator.
Thanks in advance. Looking forward to hear from you!
New information : we managed to reproduce it on an iPhone device. The Auth.signIn promise lasted 31 seconds. So it is also possible to see in an iPhone, but much harder to reproduce the error.
Anyone has any ideas? If we cannot solve it, then is there maybe a possible workaround?
Unfortunately we have had no luck trying to reproduce this issue on our end using multiple devices/simulators/emulators. However, we can still leave this issue open in case others might be experiencing it as well in the future.
one of my beta tester is facing this issue but worse. I took more than 10 minutes on her android. She tried with 3 different android in the same network wifi, same version of app and 4 iOS device with no issue.
I will be able to to more test in debug mode with this phone Friday. Don't know exactly what to look
Edit : I test to call the login in a thunk redux, in saga, or alone. Using promise or async. The result is the same. It is taking more than 10 minutes; Reactotron does not see any outgoing network request and I got no error in android studio log
I am experiencing the same issue, but with ionic+angular on android devices. "@ionic/angular": "^4.11.10", "aws-amplify": "^3.0.10", "aws-amplify-angular": "^5.0.10"
The tester is reporting a long wait time for sign in, and it seems to me that amplify is calling the cognito server about 12 times for a single Auth.signin, and the accumulated time of all these requests took this long. I am suspecting this is both related to network and the implementation of the frontend code.
one of my beta tester is facing this issue but worse. I took more than 10 minutes on her android. She tried with 3 different android in the same network wifi, same version of app and 4 iOS device with no issue.
I will be able to to more test in debug mode with this phone Friday. Don't know exactly what to look
Edit : I test to call the login in a thunk redux, in saga, or alone. Using promise or async. The result is the same. It is taking more than 10 minutes; Reactotron does not see any outgoing network request and I got no error in android studio log
When I wrote my previous message, I was getting amplify by package in react native @aws-amplify/auth api and storage.
I switch to using aws-amplify full package (with latest version) and the issue seems to have disappear. (in release mode)
Experiencing the same issue with latest expo and even clean RN. The call to SignIn can is steady at 40-60s on a clean app that just does SignIn, no other logic. Sometimes it can take up to 3 min 😮
Anyone close to a solution or a workaround?
@standemchuk If you could provide a sample repo that consistently shows this behavior, that would be wonderful! So far, I've been unable to reproduce the issue described.
@amhinson Hi and thanks for a quick reaction!
Here's a repo on which we're trying to find a fix for an issue: https://github.com/standemchuk/amplify-rn-long-response-repro
Please make sure you update the values for userPoolId and userPoolWebClientId, they're currently marked as SUBSTITUTE_ME.
@amhinson sorry, just pushed a small updated to make sure the app launches, please pull the latest changes
@amhinson were you able to reproduce the issue?
@amhinson the issue can be reproduced on android emulator and android phone only. No issues if testing in the browser (had rare issues in iOS though).
@standemchuk So far I have not been able to replicate it. Would you be able to share the steps you took after running amplify add auth? There could be a certain configuration that might be causing issues.
@amhinson, according to the docs we don't have to create authentication service from scratch by running amplify add auth, but rather we can re-use existing authentication resources.
We added amplify configuration and make a single call Auth.SignIn.
I am able to reproduce the issue now with the codebase we provide (please also see screenshots below). Sometimes we got the response within 0.5s (which is okay), but usually, it is 10 seconds or worse (81s in the second example).
Are you using any custom Lambda triggers, by chance?
@amhinson, yes we have custom triggers.
So for the sake of experiment, I've just created a new Cognito UserPool with no custom triggers.
Here are the settings of the new pool:

@rbrazhnyk Would you be able to reach out to me on our Discord? I'm still not able to reproduce the issue, but it could be helpful for me to test directly against your new User Pool.
@amhinson what is your username in Discord? amhinson does not return anything in seach results.
My username is rbrazhnyk (rbrazhnyk#7957) there. Perhaps you can ping me.
P.S. I find out how that works. I've sent you a friend request.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I have the same issue on android, it takes minutes to sign in. I can reproduce it only on android real device
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I am experiencing the exact same issue only on Android.
aws-amplify: 3.0.23 react-native: 0.63.2 custom lambda triggers for authentication: yes
any solution or workaround come from that offline discord investigation in July @rbrazhnyk @amhinson ?
@Bigbrd We were unable to reproduce the behavior on our end, unfortunately. This is still something we are actively trying to gather more data on, but it is a difficult problem to solve without being able to replicate it consistently.
If you (or anyone else who has commented on this issue) happen to have the following data from when this occurs, it would greatly help debugging efforts:
- Amplify logs -
Amplify.Logger.LOG_LEVEL = 'DEBUG' - Network request data - from a tool such as Flipper or Reactotron
@Bigbrd @amhinson I was able to reproduce the issue everytime. I stopped using aws-amplify, and switched to aws-sdk, which does not have this problem.