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

Verifying a new email causes Auth.currentAuthenticatedUser / .signIn to always return unverified email. #8169

Closed AndyW22 closed 3 years ago

AndyW22 commented 3 years ago

Before opening, please confirm:

JavaScript Framework

React

Amplify APIs

Authentication

Amplify Categories

auth

Environment information

``` # Put output below this line System: OS: macOS 11.2.3 CPU: (8) x64 Apple M1 Memory: 95.40 MB / 8.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 15.5.0 - /usr/local/bin/node Yarn: 1.22.10 - /usr/local/bin/yarn npm: 7.5.4 - /usr/local/bin/npm Browsers: Chrome: 90.0.4430.85 Firefox: 88.0 Safari: 14.0.3 npmPackages: @ampproject/toolbox-optimizer: undefined () @babel/core: undefined () @material-ui/core: ^4.11.3 => 4.11.3 @material-ui/icons: ^4.11.2 => 4.11.2 @material-ui/lab: ^4.0.0-alpha.57 => 4.0.0-alpha.57 @reduxjs/toolkit: ^1.5.0 => 1.5.1 @types/jest: ^26.0.22 => 26.0.22 @types/react: ^17.0.3 => 17.0.3 @types/react-google-recaptcha: ^2.1.0 => 2.1.0 @types/react-material-ui-form-validator: ^2.1.0 => 2.1.0 @types/redux-logger: ^3.0.8 => 3.0.8 @types/styled-components: ^5.1.9 => 5.1.9 @typescript-eslint/eslint-plugin: ^4.19.0 => 4.22.0 @typescript-eslint/parser: ^4.19.0 => 4.22.0 amphtml-validator: undefined () arg: undefined () async-retry: undefined () async-sema: undefined () aws-amplify: ^3.3.26 => 3.3.27 bfj: undefined () cacache: undefined () cache-loader: undefined () ci-info: undefined () comment-json: undefined () compression: undefined () conf: undefined () content-type: undefined () cookie: undefined () css-loader: undefined () cypress: 7.1.0 => 7.1.0 debug: undefined () devalue: undefined () escape-string-regexp: undefined () eslint: ^7.22.0 => 7.24.0 eslint-config-prettier: ^8.1.0 => 8.2.0 eslint-plugin-react: ^7.23.1 => 7.23.2 file-loader: undefined () find-cache-dir: undefined () find-up: undefined () fresh: undefined () gzip-size: undefined () http-proxy: undefined () ignore-loader: undefined () is-animated: undefined () is-docker: undefined () is-wsl: undefined () json5: undefined () jsonwebtoken: undefined () loader-utils: undefined () lodash.curry: undefined () lru-cache: undefined () mocha: ^8.3.2 => 8.3.2 mochawesome: 4.1.0 => 4.1.0 nanoid: undefined () neo-async: undefined () next: 10.0.9 => 10.0.9 next-redux-wrapper: ^7.0.0-rc.2 => 7.0.0-rc.2 ora: undefined () postcss-flexbugs-fixes: undefined () postcss-loader: undefined () postcss-preset-env: undefined () postcss-scss: undefined () prettier: ^2.2.1 => 2.2.1 react: 17.0.2 => 17.0.2 (16.14.0) react-dom: 17.0.2 => 17.0.2 (16.14.0) react-google-recaptcha: ^2.1.0 => 2.1.0 react-material-ui-form-validator: ^2.1.4 => 2.1.4 react-redux: ^7.2.3 => 7.2.3 react-responsive-modal: ^6.0.1 => 6.0.1 recast: undefined () redux-logger: ^3.0.6 => 3.0.6 resolve-url-loader: undefined () sass-loader: undefined () schema-utils: undefined () semver: undefined () send: undefined () source-map: undefined () start-server-and-test: ^1.12.1 => 1.12.1 string-hash: undefined () strip-ansi: undefined () styled-components: ^5.2.3 => 5.2.3 styled-components/macro: undefined () styled-components/native: undefined () styled-components/primitives: undefined () terser: undefined () text-table: undefined () thread-loader: undefined () typescript: ^4.2.3 => 4.2.4 unistore: undefined () web-vitals: undefined () webpack: undefined () webpack-sources: undefined () npmGlobalPackages: @aws-amplify/cli: 4.41.2 eslint: 7.16.0 nodemon: 2.0.7 npm: 7.5.4 react-devtools: 4.10.1 source-map-explorer: 2.5.2 yarn: 1.22.10 ```

Describe the bug

Updating users email will cause Auth.currentAuthenticatedUser() or Auth.signIn to always return verified_email: false despite cognito saying they are confirmed + verified.

This is very problematic as it causes a user to be permanantly locked out, if the user tries to verify their email it returns "user is already confirmed", but they can't sign in to my app because it requires a verified email. Theres no way for the user to now verify their email (since it should already be verified) and the user has to re sign up for it to work again.

Expected behavior

Once updating the users email, Auth.currentAuthenticatedUser() and Auth.signIn should be returning correct data from cognito, that the email is verified.

Reproduction steps

const data = await Auth.currentAuthenticatedUser(); await Auth.updateUserAttributes(data, { "email": email, });

Once a code is emailed:

const result = await Auth.verifyCurrentUserAttributeSubmit("email", code);

result returns "SUCCESS" and the new email is confirmed and verified on the cognito console.

const data = await Auth.currentAuthenticatedUser(); will now return the user with the correct email but it will say its unverified and it can't be changed.

Code Snippet

// Put your code below this line.

Log output

``` // Put your logs below this line ```

aws-exports.js

No response

Manual configuration

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

My auth settings:

image

stale[bot] commented 3 years ago

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.

stale[bot] commented 3 years ago

This issue has been automatically closed because of inactivity. Please open a new issue if are still encountering problems.

Khairo-kh commented 3 years ago

Hello @AndyW22! Does this issue persist after signing out then signing back in? or are you getting locked out because the email is not verified? I just tested this and it looks like everything is working fine. Can you please provide a little more details on this?

Keep in mind that Auth.currentAuthenticatedUser() without any passed parameter will use the cache to get the information about the authenticated user. This is why you will still see the property email_verified: false when calling the function with defaults (even after verifying the email). To bypass the cache and get the latest user data you can pass options as follows:

Auth.currentAuthenticatedUser({
     bypassCache: true
});

Let me know if that helps with the issue. Otherwise, please provide a little more details on how you are getting the problem and I will be happy to help!

chrisbonifacio commented 3 years ago

Hi 👋 Closing this as we have not heard back from you. If you are still experiencing this issue and in need of assistance, please feel free to comment and provide us with any information previously requested by our team members so we can re-open this issue and be better able to assist you. Thank you!

AndyW22 commented 3 years ago

Hello @AndyW22! Does this issue persist after signing out then signing back in? or are you getting locked out because the email is not verified? I just tested this and it looks like everything is working fine. Can you please provide a little more details on this?

Keep in mind that Auth.currentAuthenticatedUser() without any passed parameter will use the cache to get the information about the authenticated user. This is why you will still see the property email_verified: false when calling the function with defaults (even after verifying the email). To bypass the cache and get the latest user data you can pass options as follows:

Auth.currentAuthenticatedUser({
     bypassCache: true
});

Let me know if that helps with the issue. Otherwise, please provide a little more details on how you are getting the problem and I will be happy to help!

Can confirm that adding bypassCache to Auth.currentAuthenticatedUser fixed the issue, thanks!

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.