在Cognito用户池中注册时如何检查用户是否已经使用相同的电子邮件或电话号码存在 [英] how to check if user already exist with same email or phone number while registration in Cognito user pool
问题描述
当新用户使用相同的电子邮件和电话号码注册时,该用户已成功在Cognito用户池中注册.因此,如何在Cognito用户池中注册时检查用户是否已经使用相同的电子邮件或电话号码存在
when new user register with same email and phone number user successfully registered in the Cognito user pool. so how can i check if user already exist with same email or phone number while registration in Cognito user pool
这是我在Cognito用户池中进行用户注册的代码
This is my code for user registration in Cognito user pool
result = client.sign_up(
ClientId= clientId,
Username= data['username'],
Password= data['password'],
UserAttributes=[
{
'Name': 'phone_number',
'Value': data['phone_number'],
},
{
'Name': 'email',
'Value': data['email'],
},
{
'Name': 'custom:usertype',
'Value': data['userType']
},
],
ValidationData=[
{
'Name': 'custom:usertype',
'Value': 'required'
},
],
)
推荐答案
You can use ListUsers API call (https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_ListUsers.html) to filter users by their attributes and if it comes back with results, then you can handle user validation.
您还可以在预注册Lambda触发器"中包含此逻辑,以集中服务器端验证逻辑: https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-pre-sign-up.html
You can also contain this logic in the "Pre-Sign-up Lambda Trigger" to centralize server-side validation logic: https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-pre-sign-up.html
这篇关于在Cognito用户池中注册时如何检查用户是否已经使用相同的电子邮件或电话号码存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!