aws-amplify / amplify-flutter

A declarative library with an easy-to-use interface for building Flutter applications on AWS.
https://docs.amplify.aws
Apache License 2.0
1.31k stars 242 forks source link

Unable to send verification link via email #4540

Open erickotsuka opened 6 months ago

erickotsuka commented 6 months ago

Description

Even after overriding and setting the verification message template to CONFIRM_WITH_LINK, the method Amplify.Auth.sendUserAttributeVerificationCode still sends a code via email, ignoring what is configured in AWS Cognito. There is no method for verification link. For context, the user is being auto-confirmed during the pre-sign up Lambda trigger. After the user signs in, I want to ask them to verify the email via link.

Categories

Steps to Reproduce

  1. amplify override auth
  2. Add the following to override:
    resources.userPool.emailVerificationMessage = undefined
    resources.userPool.emailVerificationSubject = undefined
    resources.userPool.verificationMessageTemplate = {
    defaultEmailOption: 'CONFIRM_WITH_LINK',
    emailMessageByLink: `Please click the link below to verify your email address.
    {##Verify Email##}`,
    emailSubjectByLink: 'Verify your email',
    }
  3. amplify push
  4. Call Amplify.Auth.sendUserAttributeVerificationCode(userAttributeKey: AuthUserAttributeKey.email); somewhere in the app after the user is signed in
  5. Sign in to the app and make the method above be called

Screenshots

No response

Platforms

Flutter Version

3.19.2

Amplify Flutter Version

1.6.1

Deployment Method

Amplify CLI

Schema

No response

Equartey commented 6 months ago

Hi @erickotsuka, sorry you're experiencing this issue.

Can you please clarify step 1 of your reproduction steps? Where is this override occurring?

What version of Amplify CLI are you using?

Can you also please provide your amplifyconfiguration.dart file, making sure to remove any sensitive data?

erickotsuka commented 5 months ago

Ideally I should make a minimal example, I can do that in a few days, but for now I will try to describe it. If it is not enough information, I can provide a minimal example later.

  1. Create a flutter up with a sign up page that the user can enter email and password and a button to sign up.
  2. Do the amplify initialization process (https://docs.amplify.aws/flutter/start/project-setup/create-application/)
  3. amplify add auth
  4. Choose the options to allow sign in via email and password, using only Cognito (no other provider). No MFA. Add a pre sign up lambda trigger.
  5. In the pre sign up lambda trigger, set the event.response.autoConfirmUser to true and return the event.
  6. amplify override auth. This should create the file amplify/backend/auth/<app name>/override.ts
  7. Place the following in override.ts:
    
    import {
    AmplifyAuthCognitoStackTemplate,
    AmplifyProjectInfo,
    } from '@aws-amplify/cli-extensibility-helper'

export function override(resources: AmplifyAuthCognitoStackTemplate, _: AmplifyProjectInfo) { resources.userPool.emailVerificationMessage = undefined resources.userPool.emailVerificationSubject = undefined resources.userPool.verificationMessageTemplate = { defaultEmailOption: 'CONFIRM_WITH_LINK', emailMessageByLink: 'Please click the link below to verify your email address. {##Verify Email##}', emailSubjectByLink: 'Verify your email', } }


8. Change the on pressed callback for the sign up button to call, awaiting each call: `Amplify.Auth.signUp(email, password)`, then `Amplify.Auth.signIn(email, password)` and then `Amplify.Auth.sendUserAttributeVerificationCode(userAttributeKey: AuthUserAttributeKey.email)`.
9. `amplify push`
10. Run the flutter app for android in the android emulator
11. Enter a valid email and a password, then click on the sign up button
12. Check the email received. The issue is that the email being sent is with a verification code instead of a verification link

I am using version 12.10.1 of the amplify CLI.
Equartey commented 5 months ago

@erickotsuka this is really helpful, thank you. It should be sufficient to reproduce. We'll investigate and provide an update when we can.

khatruong2009 commented 5 months ago

Hi @erickotsuka, I followed your reproduction steps and was able to reproduce this issue. I'm going to mark it as a bug and we are going to discuss it as a team and will keep you updated on the next steps of this issue, thanks.

Jordan-Nelson commented 4 months ago

@erickotsuka - After speaking with Cognito, using a link confirmation is not supported for attribute confirmation. It is only supported for sign up confirmation. I will update this to a feature request. However, this would first require Cognito to support it.