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

Issue with create mutation concatenating the username twice #8071

Open
rafaelfaria opened this issue Nov 3, 2024 · 0 comments
Open

Issue with create mutation concatenating the username twice #8071

rafaelfaria opened this issue Nov 3, 2024 · 0 comments

Comments

@rafaelfaria
Copy link

rafaelfaria commented Nov 3, 2024

Describe the bug
When creating a new record using Cognito authentication in an Amplify project, the username field is being populated incorrectly. The username value appears duplicated in the format userID::userID instead of the expected single userID format. This is affecting our ability to query and manage records accurately, as the concatenated format does not match our expected schema.

It creates the record, but the response comes null for all the stuff that needs to relate to.

To Reproduce
Steps to reproduce the behavior:

  1. Define a model in the schema with a field (e.g., username) marked with @auth rules that depend on owner and allow: owner with custom ownerField.

type League @model
@auth(
rules: [
{ allow: owner, ownerField: "username" },
{ allow: private, provider: iam }
]
)
{
id: ID!
clubID: ID! @Index(name: "byClubLeague", queryField: "listLeaguesByClubId")
club: Club @belongsTo(fields: ["clubID"])
name: String!
tournaments: [Tournament] @hasmany(indexName: "byLeagueTournament", fields: ["id"])
username: String
}

  1. Use Cognito to create a new record for this model, ensuring that Cognito automatically populates the username.

async create(input: CreateLeagueInput) {

const { data } = await API.graphql(
  graphqlOperation(createLeague, { input: { ...input } })
) as CreateLeagueResult;

if (!data) {
  throw new Error('There was an issue trying to create a new league');
}

return data.createLeague;

}

  1. Query or inspect the new record, observing that the username field contains a duplicated userID::userID instead of the expected single user ID.
    You will get something like "244884a8-20c1-7099-7bab-b1e8c8eef5fb::244884a8-20c1-7099-7bab-b1e8c8eef5fb"
image

Expected behavior

The username field should only contain the user’s Cognito ID as a single value (e.g., userID), without any additional concatenation.

Desktop (please complete the following information):

  • OS: MacOS
  • Browser Chrome
  • Version 130

Additional context
The issue is occurring in an environment where we use Amplify's @auth directive with owner authorization. This unintended concatenation might be due to the IAM and Cognito configurations or a possible bug in the auto-population of owner fields by Amplify. Creating a lambda function to create the league through IAM in the backend works but is not a sustainable solution.

Besides, due to these issues, I am getting a lot of errors like below, which I am assuming is due of this issue with the double format username.

image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant