Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

confirmSignUp does not return a response when called after 'signIn' returns with 'CONFIRM_SIGN_UP' status #13876

Closed
3 tasks done
abduaddis1 opened this issue Oct 2, 2024 · 4 comments
Assignees
Labels
Auth Related to Auth components/category question General question

Comments

@abduaddis1
Copy link

abduaddis1 commented Oct 2, 2024

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

Authentication

Amplify Version

v6

Amplify Categories

auth

Backend

Amplify CLI

Environment information

# Put output below this line
  System:
    OS: macOS 14.3
    CPU: (8) arm64 Apple M2
    Memory: 85.14 MB / 24.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.8.0 - /opt/homebrew/bin/node
    Yarn: 3.6.4 - /opt/homebrew/bin/yarn
    npm: 10.8.2 - /opt/homebrew/bin/npm
    Watchman: 2024.09.02.00 - /opt/homebrew/bin/watchman
  Browsers:
    Brave Browser: 128.1.69.162
    Edge: 129.0.2792.65
  npmPackages:
    @aws-amplify/react-native: ^1.1.4 => 1.1.4 
    @aws-amplify/ui-react-native: ^2.2.5 => 2.2.5 
    @babel/core: ^7.20.0 => 7.24.5 
    @expo-google-fonts/manrope: ^0.2.3 => 0.2.3 
    @react-native-async-storage/async-storage: ^1.24.0 => 1.24.0 
    @react-native-community/netinfo: ^11.1.0 => 11.1.0 
    @react-navigation/native: ^6.1.6 => 6.1.17 
    @react-navigation/native-stack: ^6.11.0 => 6.11.0 (6.9.26)
    @react-navigation/stack: ^6.4.1 => 6.4.1 
    @types/react: ~18.2.45 => 18.2.79 
    @types/react-native-background-timer: ^2.0.2 => 2.0.2 
    @types/react-native-snap-carousel: ^3.8.11 => 3.8.11 
    HelloWorld:  0.0.1 
    aws-amplify: ^6.0.18 => 6.5.1 
    aws-amplify/adapter-core:  undefined ()
    aws-amplify/analytics:  undefined ()
    aws-amplify/analytics/kinesis:  undefined ()
    aws-amplify/analytics/kinesis-firehose:  undefined ()
    aws-amplify/analytics/personalize:  undefined ()
    aws-amplify/analytics/pinpoint:  undefined ()
    aws-amplify/api:  undefined ()
    aws-amplify/api/server:  undefined ()
    aws-amplify/auth:  undefined ()
    aws-amplify/auth/cognito:  undefined ()
    aws-amplify/auth/cognito/server:  undefined ()
    aws-amplify/auth/enable-oauth-listener:  undefined ()
    aws-amplify/auth/server:  undefined ()
    aws-amplify/data:  undefined ()
    aws-amplify/data/server:  undefined ()
    aws-amplify/datastore:  undefined ()
    aws-amplify/in-app-messaging:  undefined ()
    aws-amplify/in-app-messaging/pinpoint:  undefined ()
    aws-amplify/push-notifications:  undefined ()
    aws-amplify/push-notifications/pinpoint:  undefined ()
    aws-amplify/storage:  undefined ()
    aws-amplify/storage/s3:  undefined ()
    aws-amplify/storage/s3/server:  undefined ()
    aws-amplify/storage/server:  undefined ()
    aws-amplify/utils:  undefined ()
    expo: ^50.0.0 => 50.0.19 (51.0.28)
    expo-app-loading: ^2.1.1 => 2.1.1 
    expo-av: ~13.10.5 => 13.10.6 
    expo-blur: ~12.9.2 => 12.9.2 
    expo-cached-image: ^51.0.19 => 51.0.19 
    expo-constants: ~15.4.6 => 15.4.6 (16.0.2)
    expo-file-system: ~16.0.9 => 16.0.9 (17.0.1)
    expo-font: ~11.10.3 => 11.10.3 (12.0.9)
    expo-image: ~1.10.6 => 1.10.6 
    expo-image-picker: ~14.7.1 => 14.7.1 
    expo-linear-gradient: ^12.7.2 => 12.7.2 
    expo-linking: ~6.2.2 => 6.2.2 
    expo-router: ~3.4.10 => 3.4.10 
    expo-status-bar: ~1.11.1 => 1.11.1 
    expo-video-thumbnails: ~7.9.0 => 7.9.0 
    expo-web-browser: ~12.8.2 => 12.8.2 
    install: ^0.13.0 => 0.13.0 
    phosphor-react-native: ^2.2.0 => 2.2.0 
    react: 18.2.0 => 18.2.0 
    react-native: 0.73.6 => 0.73.6 
    react-native-background-timer: ^2.4.1 => 2.4.1 
    react-native-confirmation-code-field: ^7.4.0 => 7.4.0 
    react-native-gesture-handler: ~2.14.0 => 2.14.1 
    react-native-get-random-values: ~1.9.0 => 1.9.0 
    react-native-image-crop-picker: ^0.41.2 => 0.41.2 
    react-native-image-picker: ^7.1.2 => 7.1.2 
    react-native-modal: ^13.0.1 => 13.0.1 
    react-native-reanimated: ~3.6.2 => 3.6.3 
    react-native-reanimated-carousel: ^3.5.1 => 3.5.1 
    react-native-responsive-screen: ^1.4.2 => 1.4.2 
    react-native-safe-area-context: 4.8.2 => 4.8.2 
    react-native-screens: ~3.29.0 => 3.29.0 
    react-native-size-matters: ^0.4.2 => 0.4.2 
    react-native-snap-carousel: ^3.9.1 => 3.9.1 
    react-native-splash-screen: ^3.3.0 => 3.3.0 
    react-native-svg: 14.1.0 => 14.1.0 
    react-native-svg-transformer: ^1.5.0 => 1.5.0 
    react-native-toast-message: ^2.2.0 => 2.2.0 
    react-native-vector-icons: ^10.2.0 => 10.2.0 
    react-native-webview: ^13.6.4 => 13.6.4 
    responsive-screen:  0.1.0 
    responsive-screen-orientation-change:  0.1.0 
    responsive-screen-styled-components:  0.1.0 
    typescript: ^5.5.4 => 5.5.4 
    uuid: ^10.0.0 => 10.0.0 (9.0.1, 8.3.2, 7.0.3)
    uuidv4: ^6.2.13 => 6.2.13 
  npmGlobalPackages:
    @aws-amplify/cli: 12.10.1
    @expo/ngrok: 4.1.3
    eas-cli: 10.1.1
    expo-cli: 6.3.10
    npm-check: 6.0.1
    npm: 10.8.2
    pod-install: 0.2.2
    react-native-cli: 2.0.1
    typescript: 5.5.4


Describe the bug

I have a screen where a user can sign up or sign in to my application. The users username is their email. After the user signs up, or if the user signs in and the 'nextStep.signInStep' value is 'CONFIRM_SIGN_UP', the user is redirected to a screen where they can enter a confirmation code. This screen calls 'confirmSignUp' with the users email and the confirmation code; the only difference is, if called after 'signUp' it also calls 'autoSignIn' and if called after 'signIn' it does not.

My code for the logic of the confirmation of the signup is as follows:

 const onSubmitSignedIn = async () => {
    setLoading(true);
    console.log("Submitting OTP: ", confirmationCode);
    try {
      const response = await confirmSignUp({
        username: userEmail || '',
        confirmationCode: confirmationCode || ''
      });
      console.log("Sign up after sign in complete: ", response);

      router.push({
        pathname: 'UserAuthentication/CreatePassword',
        params: {
          userEmail: userEmail,
          userId: userId,
        }
      });
    } catch (error) {
      setOtpStatus({valid: false, message: "There was an error confirming your code; please try again or contact support"});
      console.log("Error submitting OTP: ", JSON.stringify(error));
    } finally {
      setLoading(false);
    }
  };

  const onSubmitSignedUp = async () => {
    setLoading(true);
    console.log("Submitting OTP: ", confirmationCode);
    try {
      console.log("User email: ", userEmail)
      console.log("Confrimation code: ", confirmationCode)
      const response = await confirmSignUp({
        username: userEmail || '',
        confirmationCode: confirmationCode || ''
      });
      console.log("confirmSignUp response: ", response);

      const {isSignUpComplete, nextStep} = response;
      console.log("Sign up complete");
      const {isSignedIn} = await autoSignIn();
      console.log("Autosignin response: ", JSON.stringify(isSignedIn));

      router.push({
        pathname: 'UserAuthentication/CreatePassword',
        params: {
          userEmail: userEmail,
          userId: userId,
        }
      });
    } catch (error) {
      setOtpStatus({valid: false, message: "There was an error confirming your code; please try again or contact support"});
      console.log("Error submitting OTP: ", JSON.stringify(error));
    } finally {
      setLoading(false);
    }
  };

  const onSubmitOtp = async () => {
    if (confirmationCode.length !== 6) {
      setOtpStatus({valid: false, message: "Please enter a 6-digit code"});
      return;
    }
    
    if(shouldAutoSignIn === "true") {
      await onSubmitSignedUp();
    } else {
      await onSubmitSignedIn();
    }
  };

I am getting a weird issue however; if I call 'confirmSignUp' after a user has signed up (user signs up -> verification code screen) everything works fine, and the response logs as expected; but when I call sign in and I am returned a 'CONFIRM_SIGN_UP' next step (signUp -> verification code screen -> swipe up and out of application -> restart application -> signIn with credentials -> get 'CONFIRM_SIGN_UP' status from signIn -> verification code screen -> confirmSignUp) there seems to be no response; console.log("Sign up after sign in complete: ", response); is not logged, and nothing after 'await confirmSignUp' happens; however, if I use an incorrect code, I do get a log saying it is a '{"name":"CodeMismatchException"}' error. Additionally, the confirmation does seem to happen if the 'confirmSignUp' function is run with the correct code, as the user will show up as verified in the Cognito user pool in the aws console. I do not understand why the confirmSignUp does not seem to return anything or blocks the rest of my code if it is called with the correct verification code however.

Expected behavior

The confirmSignUp function should run properly and I should get a response from confirmSignUp of type confirmSignUpOutput.

Reproduction steps

  1. Create a bare react native application setup with a bare AWS amplify configuration.
  2. Add amplify authentication
  3. Call the signUp function, do not verify with confirmSignUp, then attempt to sign in and verify user after 'CONFIRM_SIGN_UP' is returned.

Code Snippet

// Put your code below this line.

Log output

// Put your logs below this line


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_cognito_identity_pool_id": "us-east-1:e86e9a7b-XXXXX",
    "aws_cognito_region": "us-east-1",
    "aws_user_pools_id": "us-east-1XXXXXXX",
    "aws_user_pools_web_client_id": "745rq15akuktdXXXXXXX",
    "oauth": {},
    "aws_cognito_username_attributes": [
        "EMAIL"
    ],
    "aws_cognito_social_providers": [],
    "aws_cognito_signup_attributes": [
        "EMAIL"
    ],
    "aws_cognito_mfa_configuration": "OFF",
    "aws_cognito_mfa_types": [
        "SMS"
    ],
    "aws_cognito_password_protection_settings": {
        "passwordPolicyMinLength": 8,
        "passwordPolicyCharacters": []
    },
    "aws_cognito_verification_mechanisms": [
        "EMAIL"
    ],
    "aws_cloud_logic_custom": [
        {
            "name": "XXXXi",
            "endpoint": "XXXXXX",
            "region": "us-east-1"
        },
        {
            "name": "XXXX",
            "endpoint": "XXXX",
            "region": "us-east-1"
        },
        {
            "name": "XXXX",
            "endpoint": "XXXXX",
            "region": "us-east-1"
        },
        {
            "name": "XXXXXX",
            "endpoint": "XXXXXX",
            "region": "us-east-1"
        },
        {
            "name": "XXXXX",
            "endpoint": "XXXXXX",
            "region": "us-east-1"
        },
        {
            "name": "XXXXX",
            "endpoint": "XXXXX",
            "region": "us-east-1"
        }
    ],
    "aws_user_files_s3_bucket": "iXXXXXXXX",
    "aws_user_files_s3_bucket_region": "us-east-1"
};


export default awsmobile;

Manual configuration

No response

Additional configuration

No response

Mobile Device

iPhone 15

Mobile Operating System

iOS 17.4

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

@github-actions github-actions bot added pending-triage Issue is pending triage pending-maintainer-response Issue is pending a response from the Amplify team. labels Oct 2, 2024
@cwomack cwomack self-assigned this Oct 2, 2024
@cwomack cwomack added the Auth Related to Auth components/category label Oct 2, 2024
@cwomack
Copy link
Member

cwomack commented Oct 3, 2024

Hello, @abduaddis1 👋 and thanks for opening this issue. Just to confirm, the autoSignIn() API will only work with the Sign Up flow, and not with the signIn() API (see here). Are you trying to use the autoSignIn in this way?

As for the issue with confirmSignUp and getting the errors with that user, is it potentially due to the user being in a "deadlocked" state as reported in #11270?

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending a response from the Amplify team. label Oct 3, 2024
@cwomack cwomack added question General question pending-community-response Issue is pending a response from the author or community. and removed pending-triage Issue is pending triage labels Oct 3, 2024
@abduaddis1
Copy link
Author

abduaddis1 commented Oct 3, 2024

Hi @cwomack , so there is a condition to check if the user called signIn or signUp before entering the verification code, and autoSignIn() is not called unless the user had called signUp.
As to #11270 , I am confused on the 'deadlocked' state you are referring to; as far as I can see, the issue in #11270 still returns error messages even on successful email input; comment says https://github.com/aws-amplify/amplify-js/issues/11270#issuecomment-1515243017 that he gets a 'Cannot reset password for the user as there is no registered/verified email or phone_number' error message on email that exists but is not verified; meanwhile, I do not seem to get an error message when I make the call with correct arguments (incorrect verification code as an input does return an error) but I do not get a response either and no other functions will run after calling it, but the underlying function (confirming sign up) does work, as the user is shown as confirmed on the AWS console after the function call.

@github-actions github-actions bot added pending-maintainer-response Issue is pending a response from the Amplify team. and removed pending-community-response Issue is pending a response from the author or community. labels Oct 3, 2024
@cwomack
Copy link
Member

cwomack commented Oct 7, 2024

@abduaddis1, thank you for the follow up reply here. I think I've got a better understanding of the issue now based on the documentation referencing the use of CONFIRM_SIGN_UP as a nextStep property during the signIn() flow (as mentioned here). Our documentation seems to be incorrect here, as confirmSignUp() should only be called after calling the signUp API (not signIn).

Basically, the authentication flows should look like the following:

// Sign Up Flow
Call `signUp`  > Call `confirmSignUp` > (optional) Call `autoSignIn`
// Sign In Flow
Call `signIn` > Call `confirmSignIn`

Can you confirm if following the above flows (or making any changes to your code to align with them) results in this still?

Edit to add a related issue where a documentation update/fix was identified surrounding some of these Auth flows and API's - #13666

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending a response from the Amplify team. label Oct 7, 2024
@cwomack cwomack added the pending-community-response Issue is pending a response from the author or community. label Oct 7, 2024
@cwomack
Copy link
Member

cwomack commented Oct 22, 2024

Closing this issue as we have not heard back from you. If you are still experiencing this, please feel free to reply back and provide any information previously requested and we'd be happy to re-open the issue.

Thank you!

@cwomack cwomack closed this as completed Oct 22, 2024
@github-actions github-actions bot removed the pending-community-response Issue is pending a response from the author or community. label Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auth Related to Auth components/category question General question
Projects
None yet
Development

No branches or pull requests

2 participants