Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gen 2 - Amplify Outputs type issues after adding groups #14045

Closed
Drillan767 opened this issue Dec 1, 2024 · 8 comments
Closed

Gen 2 - Amplify Outputs type issues after adding groups #14045

Drillan767 opened this issue Dec 1, 2024 · 8 comments
Labels
Auth Related to Auth components/category bug Something isn't working Build Related to build issues Core Related to core Amplify issues

Comments

@Drillan767
Copy link

Drillan767 commented Dec 1, 2024

Environment information

System:
  OS: macOS 15.1.1
  CPU: (8) arm64 Apple M1
  Memory: 161.67 MB / 8.00 GB
  Shell: /bin/zsh
Binaries:
  Node: 20.15.1 - ~/.nvm/versions/node/v20.15.1/bin/node
  Yarn: 1.22.22 - ~/.nvm/versions/node/v20.15.1/bin/yarn
  npm: 10.8.3 - ~/.nvm/versions/node/v20.15.1/bin/npm
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/auth-construct: 1.5.0
  @aws-amplify/backend: 1.8.0
  @aws-amplify/backend-auth: 1.4.1
  @aws-amplify/backend-cli: 1.4.2
  @aws-amplify/backend-data: 1.2.1
  @aws-amplify/backend-deployer: 1.1.10
  @aws-amplify/backend-function: 1.8.0
  @aws-amplify/backend-output-schemas: 1.4.0
  @aws-amplify/backend-output-storage: 1.1.3
  @aws-amplify/backend-secret: 1.1.5
  @aws-amplify/backend-storage: 1.2.3
  @aws-amplify/cli-core: 1.2.0
  @aws-amplify/client-config: 1.5.2
  @aws-amplify/deployed-backend-client: 1.4.2
  @aws-amplify/form-generator: 1.0.3
  @aws-amplify/model-generator: 1.0.9
  @aws-amplify/platform-core: 1.2.2
  @aws-amplify/plugin-types: 1.5.0
  @aws-amplify/sandbox: 1.2.6
  @aws-amplify/schema-generator: 1.2.5
  aws-amplify: 6.10.0
  aws-cdk: 2.171.1
  aws-cdk-lib: 2.171.1
  typescript: 5.6.3
No AWS environment variables
No CDK environment variables

Describe the bug

Hello,

This is my first ever AWS project, so I'm not exactly certain this is a real issue, even though I can't find a solution to this problem.

I'm building a small website with both an admin and a user dashboard, so I decided to add groups. So I followed this documentation and added 2 groups, 'ADMIN' and 'USER' to my amplify/auth/resource.ts file like so:

export const auth = defineAuth({
    loginWith: {
        email: { ... },
    },
    groups: ['ADMIN', 'USER'],
    triggers: {
        postConfirmation,
    },
    access: allow => [
        allow.resource(postConfirmation).to(['addUserToGroup']),
    ],
    userAttributes: {
        'custom:role': {
            dataType: 'String',
            mutable: true,
        },
    },
})

I also followed this documentation to automate the group adding on registration process. It works well, I just set 'USER' as the group a user will join.

But when trying to build the project, I got the following errors:

Argument of type '{ auth: { user_pool_id: string; aws_region: string; user_pool_client_id: string; identity_pool_id: string; mfa_methods: never[]; standard_required_attributes: string[]; username_attributes: string[]; ... 4 more ...; unauthenticated_identities_enabled: boolean; }; data: { ...; }; storage: { ...; }; version: string; }' is not assignable to parameter of type 'ResourcesConfig | LegacyConfig | AmplifyOutputs'.
  Type '{ auth: { user_pool_id: string; aws_region: string; user_pool_client_id: string; identity_pool_id: string; mfa_methods: never[]; standard_required_attributes: string[]; username_attributes: string[]; ... 4 more ...; unauthenticated_identities_enabled: boolean; }; data: { ...; }; storage: { ...; }; version: string; }' is not assignable to type 'AmplifyOutputs'.
    The types of 'auth.groups' are incompatible between these types.
      Type '({ ADMIN: { precedence: number; }; USER?: undefined; } | { USER: { precedence: number; }; ADMIN?: undefined; })[]' is not assignable to type 'Record<string, UserGroupPrecedence>[]'.
        Type '{ ADMIN: { precedence: number; }; USER?: undefined; } | { USER: { precedence: number; }; ADMIN?: undefined; }' is not assignable to type 'Record<string, UserGroupPrecedence>'.
          Type '{ ADMIN: { precedence: number; }; USER?: undefined; }' is not assignable to type 'Record<string, UserGroupPrecedence>'.
            Property '"USER"' is incompatible with index signature.
              Type 'undefined' is not assignable to type 'UserGroupPrecedence'.

15 Amplify.configure(outputs)

The relevant part of the auto generated amplify_outputs looks like so:

{
  "auth": {
    // ...
    "groups": [
      {
        "ADMIN": {
          "precedence": 0
        }
      },
      {
        "USER": {
          "precedence": 1
        }
      }
    ]
  }
}

Is there anything I didn't do correctly or at all? The auto generated output seems good to me.

Thank you in advance

Reproduction steps

"Simply" add the following to the amplify/auth/resource.ts file:

groups: ['ADMIN' 'USER'],

And wait for the sandbox to regenerate.

@Drillan767 Drillan767 added the pending-triage Issue is pending triage label Dec 1, 2024
@ykethan
Copy link
Member

ykethan commented Dec 2, 2024

Hey @Drillan767, thank you for reaching out. Transferring the issue over to our Amplify Js repository for further investigation.

@ykethan ykethan transferred this issue from aws-amplify/amplify-backend Dec 2, 2024
@github-actions github-actions bot added the pending-maintainer-response Issue is pending a response from the Amplify team. label Dec 2, 2024
@HuiSF HuiSF added Auth Related to Auth components/category Build Related to build issues Core Related to core Amplify issues labels Dec 2, 2024
@HuiSF
Copy link
Member

HuiSF commented Dec 2, 2024

Thanks for opening this issue. I was able to reproduce the same error thrown by Typescript. It looks like TS infers the type of the following JSON object differently than what the library expects:

[
  {
    "ADMIN": {
      "precedence": 0
    }
  },
  {
    "USER": {
      "precedence": 1
    }
  }
]
// type =>
({
  ADMIN: { precedence: number; };
  USER?: undefined;
} | {
  USER: { precedence: number; };
  ADMIN?: undefined;
})[]

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending a response from the Amplify team. label Dec 2, 2024
@HuiSF
Copy link
Member

HuiSF commented Dec 2, 2024

Hi @Drillan767 sorry for the inconvenience, if you are testing only the Auth category features, could you temporarily test with this version aws-amplify@6.8.2 to get around of this type incompatibility issue while we are looking into it?

@HuiSF HuiSF added bug Something isn't working and removed pending-triage Issue is pending triage labels Dec 2, 2024
@Drillan767
Copy link
Author

Hello @HuiSF, no worries about the inconvenience, I'm just really glad you could reproduce it! I did downgrade to aws-amplify@6.8.2, and there's no longer any typescript issues, my project was able to build, thank you!

Do I keep this issue open?

@github-actions github-actions bot added the pending-maintainer-response Issue is pending a response from the Amplify team. label Dec 2, 2024
@ashwinkumar6
Copy link
Member

Thanks for confirming aws-amplify@6.8.2 has no issues, you can leave this issue open, we can close this once it's resolved on the latest version as well.

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending a response from the Amplify team. label Dec 2, 2024
@ashwinkumar6
Copy link
Member

ashwinkumar6 commented Dec 3, 2024

Hi @Drillan767,
the fix is available in unstable, could you please try clearing node_modules and lock file and test on aws-amplify@unstable if the issue is resolved

@Drillan767
Copy link
Author

Hi again @ashwinkumar6, no typescript issue on my side with the unstable version, i managed to make a build!

@github-actions github-actions bot added the pending-maintainer-response Issue is pending a response from the Amplify team. label Dec 3, 2024
@HuiSF HuiSF removed the pending-maintainer-response Issue is pending a response from the Amplify team. label Dec 3, 2024
@ashwinkumar6
Copy link
Member

ashwinkumar6 commented Dec 3, 2024

@Drillan767
Thanks for raising the issue, this is fixed on aws-amplify@6.10.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auth Related to Auth components/category bug Something isn't working Build Related to build issues Core Related to core Amplify issues
Projects
None yet
Development

No branches or pull requests

4 participants