amplify-js: No current user error
Before opening, please confirm:
- I have searched for duplicate or closed issues and discussions.
- I have read the guide for submitting bug reports.
- I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
JavaScript Framework
React Native
Amplify APIs
Authentication
Amplify Categories
auth
Environment information
System:
OS: Linux 5.11 Ubuntu 20.04.2 LTS (Focal Fossa)
CPU: (6) x64 Intel(R) Core(TM) i5-9600K CPU @ 3.70GHz
Memory: 703.03 MB / 15.31 GB
Container: Yes
Shell: 5.0.17 - /bin/bash
Binaries:
Node: 10.24.1 - ~/.nvm/versions/node/v10.24.1/bin/node
Yarn: 1.22.5 - /usr/bin/yarn
npm: 6.14.12 - ~/.nvm/versions/node/v10.24.1/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Browsers:
Chrome: 90.0.4430.85
Firefox: 92.0
npmPackages:
@babel/core: ^7.9.6 => 7.14.6
@babel/plugin-proposal-class-properties: ^7.12.1 => 7.14.5
@babel/plugin-proposal-optional-chaining: ^7.6.0 => 7.14.5
@babel/runtime: ^7.9.6 => 7.14.6
@commitlint/cli: ^7.5.2 => 7.6.1
@commitlint/config-conventional: ^7.5.0 => 7.6.0
@mapbox/polyline: ^1.1.0 => 1.1.1
@react-native-async-storage/async-storage: ^1.15.4 => 1.15.5
@react-native-community/clipboard: ^1.2.3 => 1.5.1
@react-native-community/eslint-config: ^2.0.0 => 2.0.0
@react-native-community/geolocation: ^2.0.2 => 2.0.2
@react-native-community/masked-view: ^0.1.6 => 0.1.11
@react-native-community/netinfo: ^5.9.10 => 5.9.10
@react-native-community/progress-bar-android: ^1.0.3 => 1.0.4
@react-native-community/progress-view: ^1.0.3 => 1.3.1
@react-native-community/toolbar-android: git://github.com/react-native-community/toolbar-android.git => 0.2.1
@react-native-firebase/app: ^8.3.1 => 8.4.7
@react-native-firebase/crashlytics: ^8.3.4 => 8.5.2
@sentry/react-native: ^1.8.2 => 1.9.0
@twotalltotems/react-native-otp-input: ^1.1.0 => 1.3.11
@types/d3-shape: ^1.3.1 => 1.3.8
@types/jest: ^26.0.15 => 26.0.24
@types/lodash: ^4.14.134 => 4.14.171
@types/mapbox__polyline: ^1.0.0 => 1.0.2
@types/ramda: ^0.26.9 => 0.26.44
@types/react: ^16.8.14 => 16.14.11 (17.0.14)
@types/react-native: ^0.57.49 => 0.57.65 (0.64.11)
@types/react-native-app-link: ^1.0.0 => 1.0.0
@types/react-native-i18n: ^2.0.0 => 2.0.0
@types/react-native-modalbox: ^1.4.8 => 1.4.8
@types/react-native-phone-input: ^0.2.1 => 0.2.1
@types/react-native-snap-carousel: ^3.8.2 => 3.8.4
@types/react-native-tab-view: ^2.3.0 => 2.3.0
@types/react-native-vector-icons: ^6.4.0 => 6.4.8
@types/react-native-version-check: ^3.4.0 => 3.4.1
@types/react-navigation-material-bottom-tabs: ^0.3.1 => 0.3.2
@types/react-redux: ^7.1.0 => 7.1.17
@types/react-test-renderer: 16.0.3 => 16.0.3
@types/react-timeout: ^1.1.1 => 1.1.1
@types/redux-persist: ^4.3.1 => 4.3.1
@types/seamless-immutable: ^7.1.10 => 7.1.16
@types/styled-components: ^5.1.9 => 5.1.11
@types/underscore: ^1.9.0 => 1.11.3
@types/utm: ^1.1.0 => 1.1.1
@typescript-eslint/eslint-plugin: ^4.5.0 => 4.28.2 (3.10.1)
@typescript-eslint/parser: ^4.5.0 => 4.28.2 (3.10.1)
BasicExample: 0.0.1
CustomLibraryPicker: 0.0.1
CustomPicker: 0.0.1
HelloWorld: 0.0.1
PDFExample: 0.0.1
Sample: 0.0.1
amazon-cognito-identity-js: ^5.0.2 => 5.0.3
app-icon: ^0.6.3 => 0.6.4
appcenter: 2.6.1 => 2.6.1
appcenter-analytics: 2.6.1 => 2.6.1
appcenter-crashes: 2.6.1 => 2.6.1
aws-amplify: ^4.0.3 => 4.1.2
axios: ^0.18.1 => 0.18.1 (0.21.1)
axios-retry: ^3.1.9 => 3.1.9
babel-core: ^7.0.0-bridge.0 => 7.0.0-bridge.0 (6.26.3)
babel-jest: ^26.6.3 => 26.6.3
colors: ^1.3.3 => 1.4.0
commit-prompt: ^2.2.1 => 2.2.1
crypto-js: ^3.3.0 => 3.3.0
d3-force: ^2.0.1 => 2.1.1
d3-random: ^2.0.0 => 2.2.2
d3-shape: ^1.3.5 => 1.3.7
dotenv: ^8.0.0 => 8.6.0
eslint: ^7.11.0 => 7.30.0
eslint-config-prettier: ^6.14.0 => 6.15.0
eslint-plugin-prettier: ^3.1.4 => 3.4.0 (3.1.2)
eslint-plugin-react: ^7.21.5 => 7.24.0
eslint-plugin-react-native: ^3.10.0 => 3.11.0
formik: ^2.2.9 => 2.2.9
fs: 0.0.1-security => 0.0.1-security
hermes-inspector-msggen: 1.0.0
husky: ^1.3.1 => 1.3.1
i18n-parser: ^1.0.0 => 1.0.0
jest: ^26.6.3 => 26.6.3
jetifier: ^1.6.5 => 1.6.8
lint-staged: ^8.1.5 => 8.2.1
lodash: ^4.17.11 => 4.17.21 (4.17.11)
lottie-ios: ^3.1.3 => 3.2.3
lottie-react-native: ^3.3.2 => 3.5.0
metro-react-native-babel-preset: ^0.55.0 => 0.55.0 (0.56.4)
mitt: ^1.1.3 => 1.2.0 (1.1.3)
moment: ^2.24.0 => 2.29.1
patch-package: ^6.2.2 => 6.4.7
prettier: ^1.19.1 => 1.19.1 (2.3.2)
prop-types: ^15.7.2 => 15.7.2 (15.5.8, 15.6.2)
ramda: ^0.26.1 => 0.26.1
react: 16.9.0 => 16.9.0
react-animated: 0.1.0
react-dom: ^16.8.6 => 16.14.0
react-native: 0.61.5 => 0.61.5
react-native-animatable: ^1.3.2 => 1.3.3
react-native-app-intro-slider: ^4.0.4 => 4.0.4
react-native-app-link: ^1.0.0 => 1.0.1
react-native-calendar-strip: ^2.0.7 => 2.2.3
react-native-calendars: ^1.403.0 => 1.1264.0
react-native-camera: ^3.44.1 => 3.44.3
react-native-chart-kit: ^6.6.1 => 6.11.0
react-native-circular-progress: ^1.1.0 => 1.3.7
react-native-collapsible: ^1.4.0 => 1.6.0
react-native-config: ^0.11.7 => 0.11.7
react-native-country-flags: ^1.1.0 => 1.1.0
react-native-country-picker-modal: ^1.8.1 => 1.11.0
react-native-dark-mode: ^0.2.2 => 0.2.2
react-native-device-info: ^5.5.3 => 5.6.5
react-native-disable-battery-optimizations-android: ^1.0.7 => 1.0.7
react-native-dropdown-picker: ^3.7.1 => 3.8.3
react-native-exit-app: ^1.1.0 => 1.1.0
react-native-fs: ^2.18.0 => 2.18.0
react-native-gesture-handler: ^1.5.3 => 1.10.3
react-native-gifted-chat: ^0.16.3 => 0.16.3
react-native-i18n: ~2.0.12 => 2.0.15
react-native-image-picker: ^4.0.3 => 4.0.4
react-native-interactable: ^2.0.1 => 2.0.1
react-native-iphone-x-helper: ^1.2.1 => 1.3.1
react-native-linear-gradient: ^2.5.6 => 2.5.6
react-native-localize: ^1.4.0 => 1.4.3
react-native-maps: 0.26.1 => 0.26.1
react-native-modal: ^11.5.6 => 11.10.0
react-native-modalbox: ^1.7.1 => 1.7.1
react-native-notifications: ^3.4.1 => 3.5.0
react-native-paper: ^2.15.2 => 2.16.0
react-native-pdf: ^6.0.0 => 6.3.0
react-native-permissions: ^2.0.9 => 2.2.2
react-native-phone-input: ^0.2.4 => 0.2.4
react-native-progress: ^3.6.0 => 3.6.0
react-native-ratings: ^7.3.0 => 7.6.1
react-native-reanimated: 1.9.0 => 1.9.0
react-native-responsive-screen: ^1.2.2 => 1.4.2
react-native-restart: 0.0.17 => 0.0.17
react-native-safe-area-context: ^0.6.2 => 0.6.4
react-native-safe-area-view: ^1.0.0 => 1.1.1 (0.14.9, 0.12.0)
react-native-screens: ^2.0.0-alpha.25 => 2.18.1
react-native-segmented-control-tab: ^3.4.0 => 3.4.1
react-native-smart-tip: ^2.0.1 => 2.3.0
react-native-snap-carousel: ^3.9.1 => 3.9.1
react-native-sound: ^0.11.0 => 0.11.0
react-native-splash-screen: ^3.2.0 => 3.2.0
react-native-svg: ^12.1.1 => 12.1.1
react-native-svg-animations: ^0.1.9 => 0.1.9
react-native-svg-charts: ^5.4.0 => 5.4.0
react-native-svg-transformer: ^0.14.3 => 0.14.3
react-native-text-ticker: ^1.11.0 => 1.13.0
react-native-timezone: ^1.0.3 => 1.0.3
react-native-vector-icons: ^6.6.0 => 6.7.0 (7.1.0)
react-native-version-check: ^3.4.1 => 3.4.2
react-native-walkthrough: git://github.com/danielwinkler/react-native-walkthrough#feature/PR-ts-element-multi-use => 0.2.0
react-native-walkthrough-tooltip: ^0.6.0 => 0.6.1 (1.1.7)
react-navigation: ^4.0.10 => 4.4.4
react-navigation-material-bottom-tabs: ^1.1.1 => 1.1.1
react-navigation-stack: ^2.0.15 => 2.10.4
react-navigation-tabs: ^2.7.0 => 2.11.1 (1.2.0)
react-redux: ^7.1.0 => 7.2.4
react-test-renderer: 16.6.3 => 16.6.3
react-timeout: ^1.2.0 => 1.2.0
reactotron-react-native: ^3.4.0 => 3.7.1
reactotron-redux: ^3.1.1 => 3.1.3
redux: ^4.0.1 => 4.1.0
redux-axios-middleware: ^4.0.0 => 4.0.1
redux-mock-store: ^1.5.4 => 1.5.4
redux-persist: ^5.10.0 => 5.10.0
redux-persist-transform-filter: 0.0.20 => 0.0.20
redux-persist/integration/react: undefined ()
redux-thunk: ^2.3.0 => 2.3.0
responsive-screen: 0.1.0
responsive-screen-orientation-change: 0.1.0
responsive-screen-styled-components: 0.1.0
rimraf: ^2.6.3 => 2.7.1 (3.0.2, 2.2.8)
rn-fetch-blob: ^0.11.2 => 0.11.2
rn-placeholder: ^2.0.0 => 2.0.0
seamless-immutable: ^7.1.4 => 7.1.4
sendbird: 3.0.103 => 3.0.103
src: undefined ()
styled-components: ^5.2.1 => 5.3.0
styled-components/macro: undefined ()
styled-components/native: undefined ()
styled-components/primitives: undefined ()
svg-path-properties: ^0.5.2 => 0.5.2 (0.4.11)
tslib: ^2.0.1 => 2.3.0 (1.14.1)
typescript: ^3.9.3 => 3.9.10
underscore.string: ^3.3.5 => 3.3.5
utm: ^1.1.1 => 1.1.1
yup: ^0.32.9 => 0.32.9 (0.27.0)
npmGlobalPackages:
npm: 6.14.12
Describe the bug
Sometimes for some reason we get an “No current user” error.
Expected behavior
No error
Reproduction steps
During token update
Code Snippet
const data = (await Auth.currentSession()).getIdToken();
const token = data.getJwtToken();
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
Good day!
Our users get an error from time to time when trying to update a token. We update the token like this:
const data = (await Auth.currentSession()).getIdToken(); … = data.getJwtToken();
Basically, there are no problems with this, but sometimes for some reason we get an “No current user” error.
Please tell me how can I fix this behavior?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 4
- Comments: 27 (11 by maintainers)
Yea. We still have it sometimes.
@vdhpieter Looks like you’re trying to use the Auth library in a Next application and on the server side. In your scenario, I think you should be using
withSSRContextto initialize an Auth instance using the context from the request similar to this:Note: I’m using a try/catch in my server code when checking for user info because if the “No current user” error is thrown from the server, it will page will prevent the page from loading.
For more information: https://docs.amplify.aws/lib/ssr/q/platform/js/#withssrcontext
Also worth noting - Amplify must load on the client at least once in order to detect and store in either local storage or cookie whether a user is authenticated or not. Otherwise, you’re probably going to get the “No current user” error.
See this comment: https://github.com/aws-amplify/amplify-js/issues/8011#issuecomment-839191759 and the one right after offer some more insight on how/when to handle authentication either through _app.js or separate pages.
@vdhpieter sorry, I should’ve mentioned you can also keep the
@aws-amplify/ui-reactpackage, that’s been moved to its own repository separate from our core js libraries. Also, if you would prefer to keep the scoped packages that’s okay, just need to make sure that they’re all up to date and compatible so they’re not producing duplicate instances.Are you also trying to get a user’s id/access token similarly to the code snippet shared in this issue’s description? Or are you running into it in a different context?
If you are, can you check your local storage to make sure that the type of token you’re trying to get is being stored there after authentication?
Meet this issue as well