aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.43k stars 2.12k forks source link

Auth.signIn error #7191

Closed sadooghi closed 3 years ago

sadooghi commented 3 years ago

Describe the bug After upgrade to latest version of auth (from 3.4.6 to 3.4.11) signing in username throws error:

(In '(0, _getRandomBase.default)(array.byteLength)', '(0, _getRandomBase.default)' is undefined)

To Reproduce This error is generated after Auth.signIn(username,password) is called. Prevoius version works and sign in Google/Apple/... work.

mozadeh commented 3 years ago

This seem to be more of an issue with latest version of amazon-cognito-identity-js@4.5.4. I have the same issue, when I go inside @aws-amplify/auth/node_modules and replace amazon-cognito-indentity-js with a previous version (e.g. 4.4.0) it works.

Okay I checked, with multiple amazon-cognito-identity-js version, it works up to 4.5.1 but 4.5.2 onwards gives this error.

amhinson commented 3 years ago

@sadooghi @mozadeh Could you share your package.json?

sadooghi commented 3 years ago

{ "name": "App", "version": "0.0.1", "private": true, "scripts": { "start": "react-native start", "test": "jest", "lint": "eslint ." }, "dependencies": { "@react-native-community/art": "^1.2.0", "@react-native-community/datetimepicker": "^3.0.4", "@react-native-community/masked-view": "^0.1.10", "@react-native-community/netinfo": "^5.9.7", "@react-native-community/picker": "^1.8.1", "@react-native-community/slider": "^3.0.3", "@react-native-community/voice": "^1.1.9", "@react-native-firebase/admob": "^7.6.2", "@react-native-firebase/analytics": "^8.0.1", "@react-native-firebase/app": "^9.0.0", "@react-native-firebase/crashlytics": "^8.4.2", "amazon-cognito-identity-js": "^4.5.1", "aws-amplify": "^3.3.8", "axios": "^0.21.0", "barcode-reader": "^1.6.1", "buffer": "^6.0.2", "convert-units": "^2.3.4", "create-react-class": "^15.6.3", "fraction.js": "^4.0.12", "moment": "^2.27.0", "native-base": "^2.13.14", "pluralize": "^8.0.0", "react": "16.13.1", "react-lifecycles-compat": "^3.0.4", "react-native": "^0.63.3", "react-native-animatable": "^1.3.3", "react-native-camera": "^3.40.0", "react-native-circular-action-menu": "github:mozadeh/react-native-circular-action-menu", "react-native-dialog": "^6.1.2", "react-native-dotenv": "^2.4.2", "react-native-emoji-input": "^1.1.10", "react-native-fab-pie": "github:mozadeh/react-native-fab-pie", "react-native-fast-image": "^8.3.3", "react-native-fs": "^2.16.6", "react-native-gesture-handler": "github:mozadeh/react-native-gesture-handler", "react-native-iap": "^4.6.3", "react-native-image-picker": "^2.3.4", "react-native-image-resizer": "^1.3.0", "react-native-image-viewing": "^0.2.0", "react-native-inappbrowser-reborn": "^3.5.1", "react-native-keyboard-aware-scroll-view": "github:codler/react-native-keyboard-aware-scroll-view", "react-native-linear-gradient": "^2.5.6", "react-native-loader": "github:mozadeh/react-native-loader", "react-native-loading-spinner-overlay": "^2.0.0", "react-native-masonry-scrollview": "github:mozadeh/react-native-masonry-scrollview", "react-native-material-ripple": "^0.9.1", "react-native-material-textfield": "github:mozadeh/react-native-material-textfield", "react-native-modal": "^11.5.6", "react-native-modal-datetime-picker": "^9.1.0", "react-native-multi-range": "^0.1.0", "react-native-offline": "^5.7.0", "react-native-onesignal": "^3.9.0", "react-native-popup-menu": "^0.15.9", "react-native-progress": "github:mozadeh/react-native-progress", "react-native-rate": "^1.2.4", "react-native-reanimated": "^1.13.1", "react-native-render-html": "^4.2.2", "react-native-restart": "0.0.17", "react-native-safe-area-context": "^3.1.9", "react-native-screens": "^2.14.0", "react-native-selectmultiple-button": "^0.1.105", "react-native-sendgrid": "^1.0.1", "react-native-share": "^4.1.0", "react-native-slider": "^0.11.0", "react-native-step-indicator": "^1.0.3", "react-native-svg": "^12.1.0", "react-native-svg-animated-linear-gradient": "^0.4.0", "react-native-svg-charts": "^5.4.0", "react-native-swipeable-row": "github:mozadeh/react-native-swipeable-row", "react-native-tab-view": "^2.15.1", "react-native-ui-stepper": "^1.2.4", "react-native-vector-icons": "^7.0.0", "react-native-webview": "^10.4.0", "react-navigation": "^4.4.0", "react-navigation-hooks": "^1.1.0", "react-navigation-stack": "^2.8.2", "react-navigation-tabs": "^2.9.0", "react-redux": "^7.2.1", "react-timer-mixin": "^0.13.4", "redux": "^4.0.5", "redux-actions": "^2.6.5", "redux-thunk": "^2.3.0", "rn-fetch-blob": "^0.12.0", "save": "^2.4.0", "seedrandom": "^3.0.5", "toggle-switch-react-native": "^2.3.0" }, "devDependencies": { "@babel/core": "^7.8.4", "@babel/plugin-proposal-nullish-coalescing-operator": "^7.2.0", "@babel/plugin-proposal-object-rest-spread": "^7.0.0", "@babel/preset-env": "^7.2.3", "@babel/preset-flow": "^7.0.0", "@babel/runtime": "^7.8.4", "@react-native-community/eslint-config": "^1.1.0", "babel-jest": "^25.1.0", "babel-plugin-import": "^1.6.3", "babel-plugin-transform-remove-console": "^6.9.4", "hermes-engine": "^0.5.0", "jest": "^25.1.0", "jetifier": "^1.6.6", "metro": "^0.59.0", "metro-react-native-babel-preset": "^0.59.0", "react-test-renderer": "16.13.1" }, "jest": { "preset": "react-native" } }

sadooghi commented 3 years ago

The problem is the @aws-amplify/auth/node_modules will have camazon-cognito-identity-js@4.5.4 and sign in with email does not work on that one. even though in my package.json I have amazon-cognito-identity-js@4.5.1.

amhinson commented 3 years ago

@sadooghi Could you try:

I've tried to replicate the issue you are having with a new React Native app with aws-amplify@latest and amazon-cognito-identity-js@latest but I'm still able to login.

sadooghi commented 3 years ago

Yes I tried that initially and tried - rm -rf node_modules && npm install. Login with Google/Apple works but with username it does not work.

amhinson commented 3 years ago

Could you also try running pod update in the ios folder? There were some additions to the native code within amazon-cognito-identity-js that appear to be related to the error you are seeing, so perhaps the CocoaPods just need to be updated.

maretana commented 3 years ago

We fixed this on our team by making these changes on our package.json:

"resolutions": {
    "amazon-cognito-identity-js": "4.5.1"
  },
  "dependencies": {
    "@aws-amplify/auth": "3.4.11",
    "@aws-amplify/core": "3.8.3",
    "amazon-cognito-identity-js": "4.5.1"
  }
amhinson commented 3 years ago

@maretana The latest version of amazon-cognito-identity-js should still be compatible with here, but you might be running into mismatched versions due to the modular imports, which can have unexpected behavior. We now recommend just having aws-amplify (and amazon-cognito-identity-js for React Native) in your package.json, and then letting tree-shaking handle removing any unused dependencies.

With that said, that might not be the root of the problem you are seeing. Could you also try using the latest version of amazon-cognito-identity-js and run pod update in the ios folder?

sadooghi commented 3 years ago

@amhinson thank you, yes that was the problem I think. It works right now.

jay-maas commented 3 years ago

This solved my issue to manually downgrade the package as mentioned above:

"resolutions": { "amazon-cognito-identity-js": "4.5.1" },

tbkh91 commented 3 years ago

Still an issue in 3.4.0:

    "aws-amplify": "^3.4.0",
    "aws-amplify-react-native": "^4.3.3",
    "expo": "^41.0.0",

Like mentioned by others, was able to solve it with the manual downgrade to 4.5.1:

"resolutions": {
    "amazon-cognito-identity-js": "4.5.1"
}

Prior to adding the resolutions, package-lock was referencing amazon-cognito-identity-js version 4.6.1

gruckionvit commented 3 years ago

So this was happening for me. I upgraded my expo project from version 40 to 41 and it started happening.

I have the following;

    "aws-amplify": "^3.3.17",

I upgrading aws-amplify to latest (at the time) and this resolved it.

    "aws-amplify": "^4.0.3",
siolfyr commented 3 years ago

Thanks for your hard work on this project, guys. I just want to add that this was happening for me too, and I was using version "@aws-amplify/auth": "4.0.3". It prevented sign-ins.

Not an issue for me though because I just downgraded to "@aws-amplify/auth": "3.4.11". For my purposes, this is fine.

I'm only using the auth package.

github-actions[bot] commented 2 years ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.