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

[v6] sendUserAttributeVerificationCode not send code to destination email #13432

Closed
3 tasks done
natuan62 opened this issue May 27, 2024 · 6 comments
Closed
3 tasks done
Assignees
Labels
Auth Related to Auth components/category pending-triage Issue is pending triage

Comments

@natuan62
Copy link

natuan62 commented May 27, 2024

Before opening, please confirm:

JavaScript Framework

Vue

Amplify APIs

Authentication

Amplify Version

v6

Amplify Categories

auth

Backend

None

Environment information

# Put output below this line


Describe the bug

  1. updateUserAttribute with email attributeKey
  2. sendUserAttributeVerificationCode but can't receive any code

Expected behavior

sendUserAttributeVerificationCode will works fine

Reproduction steps

  1. updateUserAttribute
  2. sendUserAttributeVerificationCode

Code Snippet

// Put your code below this line.
import {
  signIn,
  fetchUserAttributes,
  updateUserAttribute,
  confirmUserAttribute,
  UpdateUserAttributeOutput,
  sendUserAttributeVerificationCode,
} from 'aws-amplify/auth';

const handleUpdateUserAttributeNextSteps = async (output: UpdateUserAttributeOutput) => {
      const { nextStep } = output;

      switch (nextStep.updateAttributeStep) {
        case 'CONFIRM_ATTRIBUTE_WITH_CODE':
          const {codeDeliveryDetails} = nextStep;
          console.log(
            `Confirmation code was sent to ${codeDeliveryDetails?.deliveryMedium}.`,
          );
          const res = await sendUserAttributeVerificationCode({
            userAttributeKey: 'email',
          });
          console.log('sendUserAttributeVerificationCode res', res);
          // Collect the confirmation code from the user and pass to confirmUserAttribute.
          break;
        case 'DONE':
          console.log('attribute was successfully updated.');
          break;
      }
    };

const output = await updateUserAttribute({
          userAttribute: {
            attributeKey: 'email',
            value: formEmail.newEmail,
          },
        });
        console.log('updateUserAttribute output', output);
        await handleUpdateUserAttributeNextSteps(output);

Log output


 1. console.log('updateUserAttribute output', output);
=> {
    "isUpdated": false,
    "nextStep": {
        "updateAttributeStep": "CONFIRM_ATTRIBUTE_WITH_CODE",
        "codeDeliveryDetails": {
            "attributeName": "email",
            "deliveryMedium": "EMAIL",
            "destination": "l***@g***"
        }
    }
}

 2. console.log(
            `Confirmation code was sent to ${codeDeliveryDetails?.deliveryMedium}.`,
          );

=> Confirmation code was sent to EMAIL.

3. console.log('sendUserAttributeVerificationCode res', res);
=> {
    "destination": "l***@g***",
    "deliveryMedium": "EMAIL",
    "attributeName": "email"
}

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

No response

@natuan62 natuan62 added the pending-triage Issue is pending triage label May 27, 2024
@natuan62
Copy link
Author

I try to add email value field like this https://github.com/pj4269/amplify-vite-react-template/blob/12be5f0d77ca9f182d3f33e29f1cc15d828676f8/src/components/Profile.tsx#L100
But it still not working

const email = '';

await sendUserAttributeVerificationCode({
        userAttributeKey: 'email',
        email, <======
      } as SendUserAttributeVerificationCodeInput);

@israx
Copy link
Member

israx commented May 28, 2024

Hello @natuan62 . You should get a verification code when using the updateUserAttribute API and then you should be able to confirm it using the confirmUserAttribute API.

The sendUserAttributeVerificationCode API can be used to send a code for an attribute that hasn't being verified yet. Sometimes you would create a user with phone_number and email but only one of them might end up being verified during the registration and login process.

@natuan62
Copy link
Author

natuan62 commented May 28, 2024

@israx thanks for your reply. but when I using

await updateUserAttribute({
          userAttribute: {
            attributeKey: 'email',
            value: formEmail.newEmail,
          },
        });

my email on cognito changed to new email, and email_verified set to false. but it didn't receive any email for verficiation code

Did i missing some config on amplify-js, aws-config or cognito etc ?

@israx
Copy link
Member

israx commented May 28, 2024

is email configured to be an optional attribute ?

@natuan62
Copy link
Author

@israx Yes email is optional and i'm using email to signIn also
Screenshot 2024-05-28 at 22 18 28

@cwomack cwomack added the Auth Related to Auth components/category label May 28, 2024
@cwomack cwomack self-assigned this May 28, 2024
@natuan62 natuan62 closed this as completed Jun 4, 2024
@ElvisSerafim
Copy link

Hello!

I'm going through exactly this problem. How did you solve it? My email field is optional too. Do I need to change it to mandatory only or do I need to do another step?

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 pending-triage Issue is pending triage
Projects
None yet
Development

No branches or pull requests

4 participants