Search code examples
javascriptreact-nativeamazon-cognitoaws-amplifyamazon-cognito-identity-js

React native amazon-cognito-identity-js authenticateUser function too slow


I have a problem integrating library "amazon-cognito-identity-js" into react native. The authenticateUser function is too slow depending on the device:
Iphone XS: 40 seconds
Samsung galaxy A11: 70 seconds
The problem is probably in the post-processing in the library because the image below shows the api response time is only about 200 milliseconds.
I've been searching for a solution for weeks, please can anyone come across this situation and can post solution.

"react-native": "0.66.3",
"@react-native-async-storage/async-storage": "^1.17.10",
"aws-amplify": "^4.3.34",
"aws-amplify-react-native": "^6.0.5",
"amazon-cognito-identity-js": "^5.2.10",

This is response time


Solution

  • After searching for few day, finally I found the solution simply change:
    import {CognitoUser} from "amazon-cognito-identity-js"
    to:
    import {CognitoUser} from "amazon-cognito-identity-js/enhance-rn.js"
    Because the entry point of lib is js module instead of native module. So the time to compute some functions like modpow with BigInteger by js is much larger than native module => slow