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.42k stars 2.12k forks source link

currentAuthenticatedUser() throws "not authenticated" instead of the actual error that occours #8215

Closed tomerkob closed 3 years ago

tomerkob commented 3 years ago

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

Authentication

Amplify Categories

auth

Environment information

``` # Put output below this line System: OS: macOS 10.15.4 CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz Memory: 191.36 MB / 16.00 GB Shell: 5.7.1 - /bin/zsh Binaries: Node: 13.8.0 - /usr/local/bin/node Yarn: 1.22.0 - /usr/local/bin/yarn npm: 6.4.1 - ~/nutrino/Newtrino/node_modules/.bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman Browsers: Safari: 13.1 npmPackages: @babel/core: 7.6.2 => 7.6.2 (7.13.8) @babel/plugin-proposal-object-rest-spread: 7.4.4 => 7.4.4 (7.13.8) @babel/runtime: ^7.6.2 => 7.13.9 @invertase/react-native-apple-authentication: ^1.1.1 => 1.1.2 @react-native-community/async-storage: ^1.7.1 => 1.12.1 @react-native-community/cameraroll: ^4.0.1 => 4.0.2 @react-native-community/clipboard: ^1.5.0 => 1.5.1 @react-native-community/datetimepicker: ^3.0.3 => 3.0.9 @react-native-community/eslint-config: ^0.0.5 => 0.0.5 @react-native-community/geolocation: ^1.4.2 => 1.4.2 @react-native-community/google-signin: ^4.0.3 => 4.0.3 @react-native-community/image-editor: 2.3.0 => 2.3.0 @react-native-community/netinfo: ^4.1.4 => 4.7.0 @react-native-community/push-notification-ios: ^1.0.2 => 1.8.0 @redux-saga/testing-utils: ^1.1.3 => 1.1.3 @storybook/addon-storyshots: 3.4.11 => 3.4.11 @storybook/addons: 3.4.11 => 3.4.11 @storybook/channels: 3.4.11 => 3.4.11 @storybook/react-native: 3.4.11 => 3.4.11 HelloWorld: 0.0.1 Sample: 0.0.1 ajv: 6.5.4 => 6.5.4 (6.12.6, 5.5.2, 4.11.8) ajv-keywords: 3.2.0 => 3.2.0 (1.5.1) amazon-cognito-identity-js: ^4.3.3 => 4.5.12 (3.3.3) apisauce: 0.16.0 => 0.16.0 aws-amplify: 1.1.34 => 1.1.34 babel-eslint: 7.1.1 => 7.1.1 (10.0.1) babel-jest: 24.9.0 => 24.9.0 babel-plugin-ignite-ignore-reactotron: 0.3.0 => 0.3.0 babel-preset-env: 1.7.0 => 1.7.0 base-64: 0.1.0 => 0.1.0 bugsnag-react-native: 2.23.4 => 2.23.4 compare-versions: 3.4.0 => 3.4.0 convert-units: 2.3.4 => 2.3.4 enzyme: 3.7.0 => 3.7.0 enzyme-adapter-react-16: 1.15.5 => 1.15.5 example: 0.0.2 (0.0.1) format-json: 1.0.3 => 1.0.3 hermes-inspector-msggen: 1.0.0 humanize-duration: 3.15.3 => 3.15.3 husky: 0.14.3 => 0.14.3 identity-obj-proxy: 3.0.0 => 3.0.0 ignite-animatable: 1.0.0 => 1.0.0 ignite-dev-screens: 2.3.0 => 2.3.0 ignite-i18n: 1.1.1 => 1.1.1 ignite-ir-boilerplate: 2.3.3 => 2.3.3 ignite-redux-persist: 1.1.0 => 1.1.0 ignite-standard: 1.0.0 => 1.0.0 ignite-vector-icons: 1.1.0 => 1.1.0 jest: 24.9.0 => 24.9.0 jetifier: 1.6.3 => 1.6.3 (1.6.6) jwt-decode: ^2.2.0 => 2.2.0 lodash: 4.17.11 => 4.17.11 (4.17.21) lodash.isequal: 4.5.0 => 4.5.0 lz-string: 1.4.4 => 1.4.4 metro-react-native-babel-preset: 0.55.0 => 0.55.0 (0.56.4) mockery: 2.1.0 => 2.1.0 moment: 2.22.2 => 2.22.2 moment-duration-format: 2.2.2 => 2.2.2 moment-timezone: 0.5.21 => 0.5.21 npm: 6.4.1 => 6.4.1 prop-types: ^15.7.2 => 15.7.2 querystringify: 1.0.0 => 1.0.0 (2.2.0) ramda: 0.25.0 => 0.25.0 (0.23.0, 0.24.1) react: 16.9.0 => 16.9.0 react-animated: 0.1.0 react-dom: 16.4.2 => 16.4.2 react-native: 0.61.5 => 0.61.5 react-native-android-keyboard-adjust: 1.2.0 => 1.2.0 react-native-animatable: 1.3.0 => 1.3.0 react-native-appsee: 2.4.16 => 2.4.16 react-native-asset-library-to-base64: 1.1.0 => 1.1.0 react-native-background-timer: ^2.4.1 => 2.4.1 react-native-blur: 3.2.2 => 3.2.2 react-native-button: 2.3.0 => 2.3.0 react-native-camera-kit: git+https://github.com/Comocomo/react-native-camera-kit.git => 9.0.0 react-native-check-app-install: 0.0.4 => 0.0.4 react-native-check-box: 2.1.5 => 2.1.5 react-native-communications: 2.2.1 => 2.2.1 react-native-config: 0.11.7 => 0.11.7 react-native-console-time-polyfill: ^1.2.1 => 1.2.1 react-native-date-picker: 3.2.3 => 3.2.3 react-native-device-info: 5.4.1 => 5.4.1 react-native-device-settings: ^1.2.0 => 1.2.0 react-native-dismiss-keyboard: 1.0.0 => 1.0.0 react-native-exif: 0.4.0 => 0.4.0 react-native-fast-image: ^7.0.2 => 7.0.2 react-native-fbsdk: 1.0.1 => 1.0.1 react-native-firebase: ^5.6.0 => 5.6.0 react-native-fs: 2.11.17 => 2.11.17 react-native-global-props: 1.1.5 => 1.1.5 react-native-i18n: 1.0.0 => 1.0.0 react-native-image-resizer: 1.2.3 => 1.2.3 react-native-inappbrowser-reborn: ^3.4.0 => 3.5.1 react-native-keyboard-aware-scroll-view: 0.8.0 => 0.8.0 react-native-linear-gradient: 2.4.0 => 2.4.0 react-native-loading-spinner-overlay: 0.5.2 => 0.5.2 react-native-localize: ^1.3.2 => 1.4.3 react-native-material-ui: 1.30.1 => 1.30.1 react-native-mixpanel: ^1.1.4 => 1.2.5 react-native-modal: 6.5.0 => 6.5.0 react-native-modal-datetime-picker: 9.0.0 => 9.0.0 react-native-modal-picker: 0.0.16 => 0.0.16 react-native-modal-selector: 1.0.3 => 1.0.3 react-native-offline: 5.0.0 => 5.0.0 react-native-permissions: ^2.2.0 => 2.2.2 react-native-picker-select: ^6.3.3 => 6.6.0 react-native-progress: 3.5.0 => 3.5.0 react-native-push-notification: git+https://github.com/Comocomo/react-native-push-notification.git#react_native_0.60.4_sep25 => 3.1.9 react-native-search-filter: 0.1.4 => 0.1.4 react-native-select-input-ios: 1.2.0 => 1.2.0 react-native-snap-carousel: git+https://github.com/Comocomo/react-native-snap-carousel.git => 3.7.2 react-native-svg: 9.4.0 => 9.4.0 react-native-svg-charts: 5.2.0 => 5.2.0 react-native-swiper: 1.6.0-rc.3 => 1.6.0-rc.3 react-native-table-component: 1.1.8 => 1.1.8 react-native-vector-icons: 6.6.0 => 6.6.0 react-native-video: git+https://github.com/Comocomo/react-native-video.git => 5.1.1 react-native-voice: 0.3.0 => 0.3.0 react-native-webview: ^11.2.1 => 11.2.3 react-native-wheel-picker: git+https://github.com/Comocomo/react-native-wheel-picker.git => 1.2.0 react-navigation: 2.18.3 => 2.18.3 react-navigation-redux-helpers: 2.0.9 => 2.0.9 react-navigation-stack: 1.0.6 => 1.0.6 (0.7.0) react-redux: 6.0.1 => 6.0.1 react-test-renderer: 16.9.0 => 16.9.0 reactotron-react-native: 3.6.4 => 3.6.4 reactotron-redux: 3.1.1 => 3.1.1 reactotron-redux-saga: 4.2.2 => 4.2.2 redux: 4.0.1 => 4.0.1 (4.0.5) redux-persist: 5.10.0 => 5.10.0 redux-persist-transform-encrypt: git+https://github.com/Comocomo/redux-persist-transform-encrypt.git => 2.0.2 redux-persist/integration/react: undefined () redux-saga: 1.1.3 => 1.1.3 redux-saga-test-plan: ^4.0.0-rc.3 => 4.0.1 redux-saga/effects: undefined () reduxsauce: 1.0.0 => 1.0.0 seamless-immutable: 7.1.4 => 7.1.4 snazzy: 7.1.1 => 7.1.1 src: undefined () standard: 10.0.2 => 10.0.2 uuid: 3.3.2 => 3.3.2 ```

Describe the bug

currentAuthenticatedUser() throws "not authenticated" instead of the actual error. in the case of identity token is expired and the app is offline (no internet), and in the process of receiving response from currentAuthenticatedUser() amplify tries to refresh the token, and even if there is a network error, instead of throwing the actual error we get "not authenticated". which makes it impossible to differentiate when an error occurs because of unauthenticated/expired refresh token and other issue which should be handled very differently. Screen Shot 2021-05-03 at 15 34 03

Expected behavior

when currentAuthenticatedUser() fails, it should throw the actual error that occurs.

Reproduction steps

1) login with user (in my example using federated sign in with a react native app) 2) disconnect from the internet 3) wait for the identity token and access token to expire 4) call currentAuthenticatedUser() 5) catch the error that the function returns..

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

iphone12

Mobile Operating System

IOS14.2

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

chrisbonifacio commented 3 years ago

Good morning 👋 looks like you're using a two year old version (1.1.34) of aws-amplify. Would you mind upgrading to the latest version (3.3.27) and testing if this issue still occurs?

I recently had to reproduce another issue that had to do with expired tokens and this is the error I was getting on the latest version.

Screen Shot 2021-04-28 at 11 16 07 AM
frontr-uk commented 3 years ago

Hi, currently also have issue with the latest version does not call to get the token

chrisbonifacio commented 3 years ago

@frontr-uk are you experiencing the same issue? Could you post the error message or response you're getting from Cognito?

tomerkob commented 3 years ago

@chrisbonifacio it's hard for us at the moment to update to the recent version, since there are breaking changes. so for now, we've forked your repository only for auth packager use and changed only the throw action to throw the actual error only if the error thrown is not "No current user". and in our app de we're overriding auth package with our forked one. we are in the middle of testing it out

chrisbonifacio commented 3 years ago

That's understandable. I am going to close this issue as I am unable to reproduce it and it seems the correct error is being thrown in the latest version. Please feel free to re-open if you need additional help and/or let us know how the testing goes.

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.