You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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,
    ),
  ]
)
  • 额外确认两点:
    1. AWS Cognito用户池后台已经提前添加了custom:birthdate、custom:gender两个自定义属性
    2. 自定义属性的长度限制规则和你传递的值匹配,你当前使用的MM/DD/YYYY格式的birthdate长度为10位,确认属性最大长度设置≥10即可。

你现在打印的birthdate取值是正常的,这部分拼接逻辑不需要修改。

内容的提问来源于stack exchange,提问作者gs97ahn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 02:36:02