您好,我正在尝试使用内置的Angular组件进行身份验证。 我已经使用Amplify创建了Cognito和API。 无法更改Cognito用户池。 这是一个屏幕截图,您还可以在其中查看设置:
我已经像这样初始化了组件:
<ion-content padding>
<amplify-authenticator [signUpConfig]="signUpConfig" framework="ionic"></amplify-authenticator>
</ion-content>
我的课程包含用于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
}
]
};
}
不幸的是,我必须包含
{
label: 'Mobile-Username',
key: 'username',
required: true,
displayOrder: 1,
type: 'string'
},
,因为Cognito UserPool正在等待username
和mobile number
,所以基本上用手机号码填充用户名,尽管从设置中很明显,我只需要手机作为我的用户名。
如果我离开了signUpFields
的第一个条目,那么我总是从服务器收到一个错误,提示username cannot be empty
。
现在我应该做些什么,尤其是现在我无法对用户池进行任何更改。我相信这是由于我使用Amplify CLI进行了设置。
答案 0 :(得分:0)
您是否尝试过在username
参数中传递attributes
?或者在属性参数中尝试使用preferred_username
代替username
。
Auth.signUp({
username,
password,
attributes: {
'username': username // HERE or try 'preferred_username': username
},
validationData: [] //optional
}).then().catch()
基于文档
如果用户名字符串采用有效的电话号码格式,则用户池会自动使用用户名值填充用户的phone_number属性。 您可能不需要添加上面的代码。