sanity: Insufficient Permissions for message input

Describe the bug

Hi! I hope someone can help me with this issue. I apologize in advance for any missing information I may not provide due to my inexperience in coding.

I have set up a form that has a name, email, and message input what when filled out should send complete a schema to send to the sanity backend online. However whenever I click the submit button I encounter this error on my chrome console.

POST https://utsyx7w2.api.sanity.io/v2022-02-01/data/mutate/production?returnIds=true&returnDocuments=true&visibility=sync 403

ClientError {response: {…}, statusCode: 403, responseBody: '{\n "error": {\n "description": "the mutation(s)…\n }\n ],\n "type": "mutationError"\n }\n}', details: {…}, message: 'the mutation(s) failed: Insufficient permissions; permission "create" required', …} details: description: "the mutation(s) failed: Insufficient permissions; permission \"create\" required" items: [{…}] type: "mutationError" [[Prototype]]: Object response: {body: {…}, url: 'https://utsyx7w2.api.sanity.io/v2022-02-01/data/mu…turnIds=true&returnDocuments=true&visibility=sync', method: 'POST', headers: {…}, statusCode: 403, …} responseBody: "{\n \"error\": {\n \"description\": \"the mutation(s) failed: Insufficient permissions; permission \\\"create\\\" required\",\n \"items\": [\n {\n \"error\": {\n \"description\": \"Insufficient permissions; permission \\\"create\\\" required\",\n \"permission\": \"create\",\n \"type\": \"insufficientPermissionsError\"\n },\n \"index\": 0\n }\n ],\n \"type\": \"mutationError\"\n }\n}" statusCode: 403 message: "the mutation(s) failed: Insufficient permissions; permission \"create\" required" name: "ClientError" stack: "ClientError: the mutation(s) failed: Insufficient permissions; permission \"create\" required\n at onResponse (http://localhost:3000/static/js/bundle.js:4305:13)\n at applyMiddleware (http://localhost:3000/static/js/bundle.js:9677:23)\n at onResponse (http://localhost:3000/static/js/bundle.js:8908:22)\n at http://localhost:3000/static/js/bundle.js:8877:16\n at onLoad (http://localhost:3000/static/js/bundle.js:9519:5)\n at XMLHttpRequest.xhr.<computed> (http://localhost:3000/static/js/bundle.js:9382:5)" [[Prototype]]: BaseError

I have full admin privileges and believe I have the correct Token + ID for Sanity. Is there any idea as to what could be causing this?

To Reproduce

Steps to reproduce the behavior:

  1. Go to ‘https://github.com/Magowntown/am_portfolio
  2. Clone repo
  3. Run npm run start
  4. When in browser scroll to bottom and begin filling out form. When filled click submit and open developer console.

Expected behavior

The send button will change to Sending… but will not complete the send request and show the previous errors listed above.

Screenshots The Code:

image

Which versions of Sanity are you using?

Sanity v. 2.30.0

What operating system are you using?

Windows 10

Which versions of Node.js / npm are you running?

8.8.0

Additional context

Add any other context about the problem here.

Security issue?

None that I believe

Thank you in advance for any help you can provide!

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 18 (3 by maintainers)

Most upvoted comments

Hi someone find any solution? i think that the probleme is with your .env file i paste directly the token in client.js and its worked

Had the same bug and I have been able to fix it. First ensure that you’re using the correct env naming convention and import for the server your using( either Create-React-APP=REACT_APP or Vite=VITE_APP or Create-Next-App=NEXT_APP etc.). Mind you, create-react-app & create-next-app env file are imported as process.env.REACT_APP || process.env.NEXT_APP respectively but Vite env files are imported as import.meta.env.VITE_APP. And finally check to see to see if your .env file is in the root directory, in other words, outside the /src directory otherwise .env variables won’t be accessible for usage. Hope this helps you. Good luck. Happy coding!

@abroroo have you check this comment? #3284 (comment)

Try to console.log your .env values and see if they’re being injected

Yeah, the issue was that I was trying to access the token property in my component before it was fully loaded. Utils function to load the .env variables outside the component resolved the problem. Thank you!

Your API token has to be with [Editor] permission type.

For me, the problem was my dotenv configuration was not finding my .env file, so my token was getting undefined. That’s because I was calling a script from a root level (in a monorepo).