sanity
sanity copied to clipboard
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:
- Go to 'https://github.com/Magowntown/am_portfolio'
- Clone repo
- Run npm run start
- 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:
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!
exactyle also i have the same bug
Hey! Please create a new Token with 'Editor' access.
Hey! Please create a new Token with 'Editor' access.
Created the Token with 'Editor' access still same bug
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
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).
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
I have the same issue! Everything works fine when i directly use the token string. But I want to use it through .env file. Are there any solutions yet?
Your API token has to be with [Editor] permission type.
This is most likely happening because:
- The token you have don't have the correct permissions, and/or
- The token isn't properly loaded from the environment into your code.
You can confirm that the client
have the token by logging it out in the console where you run your client.create/patch
code:
console.log(client.config())
Look for the token
property in the config object.
It can also be useful to know that you can set withCredentials: true
in the client config to leverage a logged-in user's authentication client-side.
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
I have the same issue! Everything works fine when i directly use the token string. But I want to use it through .env file. Are there any solutions yet?
Hi, I have the same issue, could anybody find any solutions?
@abroroo have you check this comment? https://github.com/sanity-io/sanity/issues/3284#issuecomment-1380734349
Try to console.log your .env
values and see if they're being injected
@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.
This worked for me. Thank you.
-
If you are using Next.js then your token's env variable must have "NEXT_PUBLIC_" as prefix. eg: "NEXT_PUBLIC_SANITY_USER_ADDER_TOKEN" Then use it anywhere as: process.env.NEXT_PUBLIC_SANITY_USER_ADDER_TOKEN
-
Make sure your env file is in root directory.
-
create token with "Editor" permission in your Manage project - API Section
-
Add that token to your client.
Hey I got a solution If you guys are using vite then make sure in your .env file the name of variable starts with VITE for e.g -> VITE_REACT_SANITY_PROJECT_ID = jasdfhk3
or if you're using react you need to do like this REACT_SANITY_PROJECT_ID = sadag454
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!