aws-amplify / amplify-backend

Home to all tools related to Amplify's code-first DX (Gen 2) for building fullstack apps on AWS
Apache License 2.0
171 stars 58 forks source link

When defining the auth/resource.ts, adding custom: attributes to the userAttributes doesn't work and causes an error. #2111

Open UnclAlDeveloper opened 1 day ago

UnclAlDeveloper commented 1 day ago

Environment information

System:
  OS: Linux 5.15 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
  CPU: (8) x64 Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz
  Memory: 12.25 GB / 30.84 GB
  Shell: /bin/bash
Binaries:
  Node: 21.7.2 - ~/.nvm/versions/node/v21.7.2/bin/node
  Yarn: undefined - undefined
  npm: 10.5.1 - ~/.nvm/versions/node/v21.7.2/bin/npm
  pnpm: 9.12.1 - ~/.nvm/versions/node/v21.7.2/bin/pnpm
NPM Packages:
  @aws-amplify/backend: 1.0.4
  @aws-amplify/backend-cli: 1.1.1
  aws-amplify: 6.6.4
  aws-cdk: Not Found
  aws-cdk-lib: Not Found
  typescript: 5.5.3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!                                                                            !!
!!  Node 21 has reached end-of-life on 2024-06-01 and is not supported.       !!
!!  Please upgrade to a supported node version as soon as possible.           !!
!!                                                                            !!
!!  This software is currently running on node v21.7.2.                       !!
!!  As of the current release of this software, supported node releases are:  !!
!!  - ^22.0.0 (Planned end-of-life: 2027-04-30)                               !!
!!  - ^20.0.0 (Planned end-of-life: 2026-04-30)                               !!
!!  - ^18.0.0 (Planned end-of-life: 2025-04-30)                               !!
!!                                                                            !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
AWS environment variables:
  AWS_REGION_NAME = us-east-2
  AWS_ACCOUNT_ID = 350521974465
  AWS_STS_REGIONAL_ENDPOINTS = regional
  AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
  AWS_SDK_LOAD_CONFIG = 1
No CDK environment variables

Describe the bug

Adding custom attributes to the userAttributes section of amplify/auth/resource.ts causes an error. If a standard userAttribute is included in the userAttributes then the error is not picked up by JetBrains Rider, but the Build will fail with an error such as

amplify/auth/resource.ts(18,5): error TS2353: Object literal may only specify known properties, and '"custom:company"' does not exist in type 'StandardAttributes'.

If the userAttributes section only contains custom attributes, such as in the Custom attributes script from https://docs.amplify.aws/nextjs/build-a-backend/auth/concepts/user-attributes/ , then Rider will immediately pick up the error: Argument type {userAttributes: {"custom:favorite_number": {min: number, max: number, dataType: string, mutable: boolean}, "custom:is_beta_user": {dataType: string, mutable: boolean}, "custom:display_name": {dataType: string, mutable: boolean, minLen: number, maxLen: number}, "custom:started_free_trial": {dataType: string, mutable: boolean}}, loginWith: {email: {verificationEmailSubject: string}}} is not assignable to parameter type AmplifyAuthProps

Has there been an undocumented change to how customAttributes are added when defining the auth?

Reproduction steps

The easiest way to reproduce this bug is to follow the instructions for creating custom attributes on https://docs.amplify.aws/nextjs/build-a-backend/auth/concepts/user-attributes/

ykethan commented 19 hours ago

Hey @UnclAlDeveloper, thank you for reaching. noticed the amplify backend packages are a bit out of date.

  @aws-amplify/backend: 1.0.4
  @aws-amplify/backend-cli: 1.1.1

could you update these to the latest version and retry cognito attributes? as i was not able to reproduce the error message using the example provided in the documentation. tested this using

    "@aws-amplify/backend": "^1.4.0",
    "@aws-amplify/backend-cli": "^1.2.9",

Additionally, could you verify if the aws-cdk and aws-cdk-lib are installed in the projects root package.json?

tomburge commented 18 hours ago

Just as an FYI:

I have this same issue but its because I used the Vue starter template yesterday.

https://github.com/aws-samples/amplify-vue-template/blob/main/package.json

The starter template has ^1.0.4 but also has the package-lock.json.

The starter templates have varying versions:

Angular: 1.0.4 Next: 1.2.1 React: 1.1.1 Vue: 1.0.4 Backend Only: 1.0.4

It is probably worth it to put an advisory notice to do an npm update before trying to actually use it. While that version works for the template, it is causing me all kinds of problems with anything else. I was pulling my hair out trying to use it and not realizing what it was.