[英]AWS Cognito Amplify Authentication and Angular UI Components
Hello I am trying to use the use the built-in Angular components for authentication. 您好我正在尝试使用内置的Angular组件进行身份验证。 I have created the Cognito and the API with Amplify. 我用Amplify创建了Cognito和API。 The Cognito user pool cannot be changed. 无法更改Cognito用户池。 Here is a screenshot where you can see the setup as well: 这是一个屏幕截图,您可以在其中查看设置:
I have initialize the component like this: 我已经像这样初始化组件:
<ion-content padding>
<amplify-authenticator [signUpConfig]="signUpConfig" framework="ionic"></amplify-authenticator>
</ion-content>
My class contains this for the signUpConfig: 我的类包含了signUpConfig:
constructor(
public events: Events,
public amplifyService: AmplifyService,
public router: Router
) {
this.authState = { signedIn: false };
this.signUpConfig = {
header: "SignUp",
defaultCountryCode: '30',
hideAllDefaults: true,
signUpFields: [
{
label: 'Mobile-Username',
key: 'username',
required: true,
displayOrder: 1,
type: 'string'
},
{
label: 'Mobile',
key: 'phone_number',
required: true,
displayOrder: 2,
type: 'string'
},
{
label: 'Password',
key: 'password',
required: true,
displayOrder: 3,
type: 'password'
},
{
label: 'Email',
key: 'email',
required: true,
displayOrder: 4,
type: 'email'
},
{
label: 'Name',
key: 'name',
required: true,
displayOrder: 5,
type: 'string'
},
{
label: 'Surname',
key: 'family_name',
required: true,
displayOrder: 6,
type: 'string'
},
{
label: 'Address',
key: 'address',
required: true,
displayOrder: 7
},
{
label: 'Gender',
key: 'gender',
required: true,
displayOrder: 8
}
]
};
}
Unfortunately I have to include the 不幸的是,我必须包括
{
label: 'Mobile-Username',
key: 'username',
required: true,
displayOrder: 1,
type: 'string'
},
in order to populate the username with the mobile number basically since the Cognito UserPool is waiting for a username
and a mobile number
although it is clear from the settings that I need only mobile as my username. 为了使用手机号码填充用户名,因为Cognito UserPool正在等待username
和mobile number
尽管从设置中可以清楚地知道我只需要移动设备作为我的用户名。
If I leave the first entry from my signUpFields
then I always receive an error from the server that the username cannot be empty
. 如果我从signUpFields
保留第一个条目,那么我总是从服务器收到一个错误,即username cannot be empty
。
What am I supposed to do especially now that I cannot do any changes on my user pool. 我应该做什么,特别是现在我无法对我的用户池进行任何更改。 I believe this is due to the fact that I used the Amplify CLI to setup it. 我相信这是因为我使用Amplify CLI来设置它。
Have your tried passing username
in the attributes
parameters? 您是否尝试过在attributes
参数中传递username
? Or try preferred_username
instead of username
in the attributes parameter. 或者在attributes参数中尝试使用preferred_username
而不是username
。
Auth.signUp({
username,
password,
attributes: {
'username': username // HERE or try 'preferred_username': username
},
validationData: [] //optional
}).then().catch()
Based on the documentation 根据文档
If the username string is in valid phone number format, the user pool automatically populates the phone_number attribute of the user with the username value. 如果用户名字符串是有效的电话号码格式,则用户池会自动使用用户名值填充用户的phone_number属性。 You might not need to add the code above. 您可能不需要添加上面的代码。
Link: https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-attributes.html#user-pool-settings-aliases 链接: https : //docs.aws.amazon.com/cognito/latest/developerguide/user-pool-settings-attributes.html#user-pool-settings-aliases
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.