aws-amplify / aws-amplify/docs

Issue with create mutation concatenating the username twice

Open
#8,071 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
MDX
Stars
506
Forks
1.1k
Avg merge
3h 14m
Merged PRs (30d)
1

Description

**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
}

2. 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;
}

3. 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.