‘Unauthorized’ error when using AWS amplify with grahql to create a new user

Question:

So I think this issue comes from me not quite understanding the relationship between AWS cognito user pools and the auth rules in a graphql schema.

When I run the code below, I get the message “Not Authorized to access createUser on type User”.

Other relevant code would be my index.js:

And the schema definition for the User object:

Ultimately, I’m trying to make something similar to this example. I’ve tried reading the aws amplify docs but haven’t been able to properly understand how the graphql operations are effected by the authentication.

Answer:

I just spent several hours battling this same issue. For me, I had to specify the authMode on the graphql request.

Rather than doing something like this:

I had to use this:

I did try the solution from user patwords. However, nothing I did on the schema was effective (including adding @aws_cognito_user_pools as indicated).

Unfortunately, the Amplify documentation does not do a good job documenting the process. I hope this helps someone else save a bit of time.

Leave a Reply