【发布时间】:2019-11-24 03:34:09
【问题描述】:
在我的 Android 应用中,我希望我的用户能够更改他们的电子邮件地址(他们用来连接到他们的帐户),而无需通过电子邮件获得任何验证码。
到目前为止,我设法更改了电子邮件地址,并且感谢 lambda,将 email_verified 自动设置为 true。但不幸的是,仍然会发送一封带有验证码的电子邮件...
这是我在 Android 应用中所做的:
public void onClickChangeEmail(View view)
{
CognitoUserAttributes attributes = new CognitoUserAttributes();
attributes.getAttributes().put("email", "second@mail.com");
CognitoSettings
.getCognitoUserPool(MainActivity.this)
.getCurrentUser()
.updateAttributesInBackground(attributes, new UpdateAttributesHandler()
{
@Override
public void onSuccess(List<CognitoUserCodeDeliveryDetails> attributesVerificationList)
{
Log.i("tag", "Email updated!");
}
@Override
public void onFailure(Exception e)
{
e.printStackTrace();
}
});
}
在我的 AWS 控制台中,我在 Cognito 的 自定义消息 上添加了一个触发器,这是我的 lambda 函数,每次用户更新他的电子邮件时都会触发:
const AWS = require('aws-sdk')
AWS.config.update({region: 'eu-central-1'});
exports.handler = (event, context, callback) => {
if (event.triggerSource === 'CustomMessage_UpdateUserAttribute')
{
const params = {
UserAttributes: [
{
Name: 'email_verified',
Value: 'true',
},
],
UserPoolId: event.userPoolId,
Username: event.userName,
};
var cognitoIdServiceProvider = new AWS.CognitoIdentityServiceProvider();
cognitoIdServiceProvider.adminUpdateUserAttributes(params, function(err, data) {
if (err) context.done(err, event); // an error occurred
else context.done(null, event); // successful response
});
}
else
{
context.done(null, event);
}
};
我发现的唯一解决方法是抛出错误而不是 context.done(null, event);,但它看起来不像是一个干净的解决方案。
有没有更好更简洁的方法来阻止 Cognito 发送验证电子邮件?
感谢您的帮助。
【问题讨论】:
标签: amazon-web-services amazon-cognito