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

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

Closed natuan62 closed 3 months ago

natuan62 commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

@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 commented 4 months ago

is email configured to be an optional attribute ?

natuan62 commented 4 months ago

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