Flutter接入AWS Cognito注册时报InvalidParameterException如何解决?
报错原因
从报错日志可以定位到问题出在Cognito自定义属性的命名上:你传递的custom:birthdate:属性名末尾多了一个多余的冒号,不符合Cognito要求的属性名正则规则(仅允许字母、数字、下划线、点、横杠,冒号仅用于分隔custom前缀和属性名,不能出现在属性名末尾)。
解决步骤
- 检查
SignUpCredentials类的实现,确认birthdate对应的Cognito属性名是否多写了末尾的冒号,修正为custom:birthdate即可。 - 如果你是通过Amplify的
AuthUserAttribute构造用户属性,参考以下正确写法:
AuthSignUpOptions( userAttributes: [ AuthUserAttribute( userAttributeKey: AuthUserAttributeKey.email, value: email, ), AuthUserAttribute( userAttributeKey: AuthUserAttributeKey('custom:gender'), value: gender, ), // 注意属性名末尾没有多余冒号 AuthUserAttribute( userAttributeKey: AuthUserAttributeKey('custom:birthdate'), value: birthdate, ), ] )
- 额外确认两点:
- AWS Cognito用户池后台已经提前添加了
custom:birthdate、custom:gender两个自定义属性 - 自定义属性的长度限制规则和你传递的值匹配,你当前使用的
MM/DD/YYYY格式的birthdate长度为10位,确认属性最大长度设置≥10即可。
- AWS Cognito用户池后台已经提前添加了
你现在打印的birthdate取值是正常的,这部分拼接逻辑不需要修改。
内容的提问来源于stack exchange,提问作者gs97ahn
相关产品推荐
相关产品推荐

