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

Confirming Sign Up with AWS Auth with Verification Code does not set phone_number_verified to "true" automatically #12698

Closed ChristopherGabba closed 9 months ago

ChristopherGabba commented 9 months ago

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

Authentication

Amplify Categories

auth

Environment information

``` System: OS: macOS 14.0 CPU: (10) arm64 Apple M2 Pro Memory: 672.66 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.7.0 - /opt/homebrew/bin/node npm: 10.1.0 - /opt/homebrew/bin/npm Watchman: 2023.09.04.00 - /opt/homebrew/bin/watchman Browsers: Safari: 17.0 npmPackages: @aws-amplify/ui-react-native: ^1.2.28 => 1.2.28 @babel/core: ^7.20.0 => 7.23.2 @babel/plugin-proposal-export-namespace-from: ^7.18.9 => 7.18.9 @babel/preset-env: ^7.20.0 => 7.23.2 @babel/runtime: ^7.20.0 => 7.23.2 @expo-google-fonts/m-plus-1p: ^0.2.3 => 0.2.3 @expo-google-fonts/montserrat: ^0.2.3 => 0.2.3 @expo-google-fonts/space-grotesk: ^0.2.2 => 0.2.3 @expo/config-plugins: ^7.2.5 => 7.2.5 (5.0.4) @expo/metro-config: ^0.10.7 => 0.10.7 @gorhom/bottom-sheet: ^4.4.7 => 4.5.1 @likashefqet/react-native-image-zoom: ^2.1.1 => 2.1.1 @react-native-async-storage/async-storage: 1.18.2 => 1.18.2 @react-native-clipboard/clipboard: ^1.11.2 => 1.12.1 @react-native-community/cli-platform-ios: ^8.0.2 => 8.0.6 (11.3.10, 11.3.7) @react-native-community/netinfo: 9.3.10 => 9.3.10 @react-native-picker/picker: ^2.5.1 => 2.5.1 @react-navigation/bottom-tabs: ^6.3.2 => 6.5.11 @react-navigation/native: ^6.0.2 => 6.1.9 @react-navigation/native-stack: ^6.0.2 => 6.9.17 @rnx-kit/metro-config: ^1.3.5 => 1.3.12 @rnx-kit/metro-resolver-symlinks: ^0.1.26 => 0.1.34 @shopify/flash-list: 1.4.3 => 1.4.3 @types/i18n-js: 3.8.2 => 3.8.2 @types/jest: ^29.2.1 => 29.5.7 @types/react: ~18.2.14 => 18.2.34 @types/react-test-renderer: ^18.0.0 => 18.0.5 @typescript-eslint/eslint-plugin: ^5.59.0 => 5.62.0 @typescript-eslint/parser: ^5.59.0 => 5.62.0 HelloWorld: 0.0.1 amazon-cognito-identity-js: ^6.3.6 => 6.3.6 amazon-cognito-identity-js/internals: undefined () apisauce: 2.1.5 => 2.1.5 aws-amplify: ^5.3.11 => 5.3.11 axios: ^1.5.0 => 1.6.0 (0.26.0, 0.21.4) babel-jest: ^29.2.1 => 29.7.0 babel-loader: 8.2.5 => 8.2.5 babel-plugin-root-import: ^6.6.0 => 6.6.0 cheerio: ^1.0.0-rc.12 => 1.0.0-rc.12 core-util-is: 1.0.1 date-fns: ^2.29.2 => 2.30.0 eslint: 8.17.0 => 8.17.0 eslint-config-prettier: 8.5.0 => 8.5.0 eslint-config-standard: 17.0.0 => 17.0.0 eslint-plugin-import: 2.26.0 => 2.26.0 eslint-plugin-n: ^15.0.0 => 15.7.0 eslint-plugin-node: 11.1.0 => 11.1.0 eslint-plugin-promise: 6.0.0 => 6.0.0 eslint-plugin-react: 7.30.0 => 7.30.0 eslint-plugin-react-native: 4.0.0 => 4.0.0 expo: ^49.0.7 => 49.0.16 expo-application: ~5.3.0 => 5.3.1 expo-av: ~13.4.1 => 13.4.1 expo-blur: ~12.4.1 => 12.4.1 expo-camera: ~13.4.4 => 13.4.4 expo-clipboard: ~4.3.1 => 4.3.1 expo-config-plugin-ios-share-extension: ^0.0.4 => 0.0.4 expo-constants: ~14.4.2 => 14.4.2 expo-contacts: ~12.2.0 => 12.2.0 expo-dev-client: ~2.4.11 => 2.4.11 expo-device: ~5.4.0 => 5.4.0 expo-file-system: ~15.4.4 => 15.4.4 expo-font: ~11.4.0 => 11.4.0 expo-image: ^1.5.1 => 1.5.1 expo-image-picker: ~14.3.2 => 14.3.2 expo-linear-gradient: ~12.3.0 => 12.3.0 expo-linking: ~5.0.2 => 5.0.2 expo-localization: ~14.3.0 => 14.3.0 expo-media-library: ~15.4.1 => 15.4.1 expo-notifications: ~0.20.1 => 0.20.1 expo-splash-screen: ^0.20.5 => 0.20.5 expo-status-bar: ~1.6.0 => 1.6.0 expo-store-review: ~6.4.0 => 6.4.0 expo-video-thumbnails: ~7.4.0 => 7.4.0 fbjs-scripts: 3.0.1 => 3.0.1 firebase: ^10.3.1 => 10.5.2 firebase/analytics: undefined () firebase/app: undefined () firebase/app-check: undefined () firebase/auth: undefined () firebase/auth/cordova: undefined () firebase/compat: undefined () firebase/compat/analytics: undefined () firebase/compat/app: undefined () firebase/compat/app-check: undefined () firebase/compat/auth: undefined () firebase/compat/database: undefined () firebase/compat/firestore: undefined () firebase/compat/functions: undefined () firebase/compat/installations: undefined () firebase/compat/messaging: undefined () firebase/compat/performance: undefined () firebase/compat/remote-config: undefined () firebase/compat/storage: undefined () firebase/database: undefined () firebase/firestore: undefined () firebase/firestore/lite: undefined () firebase/functions: undefined () firebase/installations: undefined () firebase/messaging: undefined () firebase/messaging/sw: undefined () firebase/performance: undefined () firebase/remote-config: undefined () firebase/storage: undefined () i18n-js: 3.9.2 => 3.9.2 inherits: 2.0.1 isarray: 0.0.1 jest: ^29.2.1 => 29.7.0 jest-circus: 29 => 29.7.0 jest-environment-node: 29 => 29.7.0 jest-expo: ^49.0.0 => 49.0.0 jsdom: ^22.1.0 => 22.1.0 (20.0.3) jsdom-jscore-rn: ^0.1.8 => 0.1.8 lodash: ^4.17.21 => 4.17.21 lodash.filter: ^4.6.0 => 4.6.0 lottie-react-native: ^5.1.6 => 5.1.6 metro-config: 0.75.1 => 0.75.1 (0.76.8) metro-react-native-babel-preset: 0.75.1 => 0.75.1 (0.76.8) metro-source-map: 0.75.1 => 0.75.1 (0.76.8) mobx: 6.6.0 => 6.6.0 mobx-react-lite: 3.4.0 => 3.4.0 mobx-state-tree: 5.1.5 => 5.1.5 mocha: ^10.2.0 => 10.2.0 nwmatcher: 1.4.3 patch-package: ^6.4.7 => 6.5.1 path-browserify: 0.0.0 postinstall-prepare: 1.0.1 => 1.0.1 prettier: 2.8.8 => 2.8.8 query-string: ^7.0.1 => 7.1.3 (6.10.1) querystring: 0.2.0 react: 18.2.0 => 18.2.0 react-devtools-core: 4.24.7 => 4.24.7 (4.28.5) react-dom: 18.2.0 => 18.2.0 react-native: 0.72.7 => 0.72.7 react-native-animated-pagination-dots: ^0.1.73 => 0.1.73 react-native-bootsplash: ^5.0.2 => 5.0.4 react-native-element-dropdown: ^2.9.0 => 2.10.0 react-native-fs: ^2.20.0 => 2.20.0 react-native-gesture-handler: ~2.12.0 => 2.12.1 react-native-get-random-values: ^1.9.0 => 1.9.0 react-native-mmkv: ^2.11.0 => 2.11.0 react-native-pager-view: 6.2.0 => 6.2.0 react-native-reanimated: ~3.3.0 => 3.3.0 react-native-receive-sharing-intent: ^2.0.0 => 2.0.0 react-native-render-html: ^6.3.4 => 6.3.4 react-native-safe-area-context: 4.6.3 => 4.6.3 react-native-screens: ~3.22.0 => 3.22.1 react-native-share-menu: ^6.0.0 => 6.0.0 react-native-static-safe-area-insets: ^2.2.0 => 2.2.0 react-native-touchable-scale: ^2.2.0 => 2.2.0 react-native-url-polyfill: ^2.0.0 => 2.0.0 (1.3.0) react-native-vision-camera: ^3.6.6 => 3.6.6 react-native-volume-manager: ^1.10.0 => 1.10.0 react-native-web: ~0.19.6 => 0.19.9 react-native-webview: 13.2.2 => 13.2.2 react-native-youtube-iframe: ^2.3.0 => 2.3.0 react-test-renderer: 18.2.0 => 18.2.0 reactotron-core-client: ^2.8.10 => 2.8.10 (2.8.9) reactotron-mst: 3.1.4 => 3.1.4 reactotron-react-js: ^3.3.7 => 3.3.8 reactotron-react-native: 5.0.3 => 5.0.3 regenerator-runtime: ^0.13.4 => 0.13.11 (0.14.0) string_decoder: 0.10.31 ts-jest: 29 => 29.1.1 typescript: ^4.9.4 => 5.2.2 urlmaster: 0.2.15 npmGlobalPackages: @aws-amplify/cli-internal: 12.8.2 @aws-amplify/cli: 12.6.0 @react-native-community/netinfo: 9.4.1 eas-cli: 5.9.1 expo-cli: 6.3.10 firebase-tools: 11.24.1 n: 9.1.0 node: 20.6.0 pod-install: 0.1.39 react-native-spinkit: 1.5.1 ```

Describe the bug

When entering in a 6 digit phone code properly using the Auth.confirmSignUp() function, it correctly shows it as "CONFIRMED" in the AWS Amplify console, but does not update the user attribute of "phone_number_verified" to true:

console.log output

const currentUserInfo = await Auth.currentUserInfo()
console.log(currentUserInfo)
{"attributes": {"birthdate": "XX/XX/XXXX", "family_name": "ABCDE", "given_name": "ABCDE", "phone_number": "+1XXXXXXXXXX", "phone_number_verified": false, "sub": "user_id_string" }, "id": "cognito_id_string", "username": "username"}

But in AWS console, it is updating it to true:

Screenshot 2023-12-12 at 10 26 29 AM

Expected behavior

I would expect this phone_number_verified attribute of AWS auth to not have to be set manually and be set automatically upon verification code entry.

Reproduction steps

  1. Use typical AWS Amplify authentication using username, phone number, here is my cognito configuration: Screenshot 2023-12-12 at 10 29 46 AM
  2. Enter in the 6 digit verification code that pops up
  3. I'm using the Hub.listen function like so to navigate to next screen:
  useEffect(() => {
    const authUnsubscribe = Hub.listen("auth", (data) => {
      console.log("auth changed states")
      setAuthToggled((prev) => !prev)
      const authChange = data?.payload?.event
      switch (authChange) {
        case "autoSignIn":
          console.log("User entered in correct verification code")
          setProp("authToken", data?.payload?.data?.signInUserSession?.accessToken?.jwtToken)
          break
        case "signIn":
          console.log("user signed in normally")
          setProp("authToken", data?.payload?.data?.signInUserSession?.accessToken?.jwtToken)
          break
        case "signOut":
          console.log("user signed out")
          setProp("authToken", "")
          break
      }
    })
    return () => {
      authUnsubscribe()
    }
  }, [])

Here is my 6 digit verification code function:

useEffect(() => {
    ;(async function submitVerificationCode() {
      if (verificationCode.length === 6) {
        setIsLoading(true)
        await Auth.confirmSignUp(username, verificationCode)
          .then(() => {
            mmkvStorage.set("isFirstLogin", true)
            console.log("successfully updated username and logged in")
          })
          .catch((error) => {
            setErrorCode(error.message)
            setIsLoading(false)
          })
      }
    })()
  }, [verificationCode])

It properly navigates and detects the autoSignIn and functions correctly but the user attribute prop is just not updated automatically.

Code Snippet

Code listed above.

Log output

No error messages displayed.

aws-exports.js

/ eslint-disable / // WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.

const awsmobile = { "aws_project_region": "us-east-1", "aws_appsync_graphqlEndpoint": "https://5tvnvesrgjfjdclupp5rzrh5gi.appsync-api.us-east-1.amazonaws.com/graphql", "aws_appsync_region": "us-east-1", "aws_appsync_authenticationType": "API_KEY", "aws_appsync_apiKey": "da2-etlknfdzg5ezzcwy4jqhqsyu7e", "aws_cognito_identity_pool_id": "us-east-1:a2d5d29b-d69d-46d6-81c3-c6dc71323225", "aws_cognito_region": "us-east-1", "aws_user_pools_id": "us-east-1_eDAImGHL9", "aws_user_pools_web_client_id": "4uj0jgf4p8m3au9h8u6g429111", "oauth": {}, "aws_cognito_username_attributes": [], "aws_cognito_social_providers": [], "aws_cognito_signup_attributes": [ "GIVEN_NAME", "FAMILY_NAME", "BIRTHDATE", "PHONE_NUMBER" ], "aws_cognito_mfa_configuration": "OFF", "aws_cognito_mfa_types": [], "aws_cognito_password_protection_settings": { "passwordPolicyMinLength": 8, "passwordPolicyCharacters": [ "REQUIRES_LOWERCASE", "REQUIRES_UPPERCASE", "REQUIRES_NUMBERS", "REQUIRES_SYMBOLS" ] }, "aws_cognito_verification_mechanisms": [ "PHONE_NUMBER" ], "aws_user_files_s3_bucket": "reelfeelmedia", "aws_user_files_s3_bucket_region": "us-east-1" };

export default awsmobile;

Manual configuration

No response

Additional configuration

No response

Mobile Device

iPhone 12

Mobile Operating System

iOS 17

Mobile Browser

N/A

Mobile Browser Version

N/A

Additional information and screenshots

No response

nadetastic commented 9 months ago

Hi @ChristopherGabba thank you for opening this issue. To clarify the Confirmation status and Verification values are different - where Confirmation status represents a user who has confirmed their account after sign in, while the Verification values are specific to attributes (email, phone etc).

Could you clarify the value of Phone Number Verified attribute for the user in addition to Confirmation status?

Here's an example of a user with "Confirmation status" and "Email verified attribute" - there will be an equivalent "Phone number verified" attribute:

user
ChristopherGabba commented 9 months ago

Hello again @nadetastic, you helped me with a past issue and I really appreciate it!

After submitting this issue, I spent quite a while troubleshooting it and for some reason, it literally started working and I can't explain why. I didn't update anything, I just did a bunch of different sign ins and they all seemed to update the "phone_number_verified" attribute correctly. A few times I did it this morning, they were not in sync and the verified attribute was not updating. It would show "Confirmed" in the Amplify studio for the user, but the "phone_number_verified" would still print out "false".

I see, so in your screenshot they are actually listed differently, my studio portal doesn't show the "Phone number verified" column. That's quite confusing as I would imagine confirming a user and verifying a user are the same thing.

Regardless, I think you may be able to close this issue given the fact that it appears that things are syncing up again. Thanks again, Chris

nadetastic commented 9 months ago

@ChristopherGabba glad to be of help! Also happy to hear that the issue was temporary. From what it sounded like it was on the Cognito side of things where the syncing was not happening properly but it appears to be resolved now. I'll go ahead and mark this issue as solved but let me know if you have any other questions!