Skip to content

Amplify Data Update is failing with strange error

0

I am using Amplify Gen2 with Vue to create my app..

I created my data and give access rights to it using:

authorization((allow) => [
          allow.authenticated().to(["read"]), // All users can read
          allow.group("Admin").to(["update"]), // Only the assigned admin can update/delete
      ]),

I have no problem reading the data, but when i am trying to update it, its getting problematic..

        const response = await client.models.School.update({
            id: id,
            updates: {
                YYYY: 5,
            },
            authMode: "userPool"
        });

but am receiving

auth_utils.js:77 Error updating school info: TypeError: Cannot destructure property 'isReadOnly' of 'fields7[fieldName]' as it is undefined.

what is fields7[fieldName] even mean.. does it mean i dont have access to the data?

Also i tried to chec the fields with :

 console.log("Available model fields:", client.models.School.fields);

but i am getting: Available model fields: undefined

so model fields are not defined? As i said i have no problem reading it with signed in user using userPool

asked a year ago287 views

2 Answers
1

The error you're encountering suggests there might be an issue with how the model fields are defined or accessed in your Amplify Gen2 setup. The "fields7[fieldName]" error is likely an internal error from the Amplify library, indicating it's having trouble accessing or processing the fields of your School model.

Given that you can read the data but not update it, there are a few potential issues to consider:

  1. Authorization: Your authorization rules allow only the "Admin" group to perform updates. Make sure the user you're using to test the update operation is actually in the "Admin" group.

  2. Model definition: There might be an issue with how your School model is defined. Double-check your schema definition to ensure all fields, especially 'YYYY', are correctly specified.

  3. Field visibility: The fact that client.models.School.fields is undefined is unusual and could indicate a problem with how the model is being generated or accessed in your client-side code.

  4. Auth mode: You're using "userPool" as the authMode. While this is generally correct for authenticated operations, ensure that your Amplify configuration is set up to use Cognito User Pools correctly.

To troubleshoot:

  1. Verify that your user is in the "Admin" group.
  2. Double-check your schema definition for the School model.
  3. Ensure that your Amplify CLI version is up to date.
  4. Try using the Amplify Console to view and verify your data model.
  5. Check if there are any errors during the Amplify push or codegen processes.

If the issue persists, you might want to try recreating the data model or reaching out to AWS support for more detailed assistance, as this seems to be an unusual error that might require a deeper look into your specific setup.
Sources
How to Build Next.js Apps with Authentication using AWS Amplify and Auth0 | Front-End Web & Mobile
Full Stack Development - Web and Mobile Apps - AWS Amplify
Issue with amplify gen2 file upload using Storage: access denied | AWS re:Post

answered a year ago

EXPERT

reviewed a year ago

  • Verify that your user is in the "Admin" group. Double-check your schema definition for the School model. Ensure that your Amplify CLI version is up to date. Try using the Amplify Console to view and verify your data model. Check if there are any errors during the Amplify push or codegen processes.

    I checked all those steps... without success...

0

I ran into this issue because I was using allow.owner() as one of my auth rules, and even when owner was set properly on the record, I would get the weird error mentioned by OP. This has been logged as an issue here, and I think the issue has been erroneously marked as "fixed" (the fix in the issue is to use "UserPool" instead of "API Key" as the auth mechanism, but I'm already doing that). My code can be found at one of the last comments (comment made by keithrz, Monday Mar 24)

One workaround is to remove allow.owner() from the list of authorization rules, but I do not like that approach.

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.