appwrite
appwrite copied to clipboard
🐛 Bug Report: Can't create document as anonymous user
👟 Reproduction steps
I have created an anonymous session in react and proceeded to post a document in my appwrite but its showing an error message as i mentioned below
👍 Expected behavior
I need to create a document in my collections but it needs (document.write) permission in order to create a document in my collection
👎 Actual Behavior
POST 401 (Unauthorized)
AppwriteException: User (role: guest) missing scope (documents.write)
at Appwrite.
🎲 Appwrite version
Version 0.12.x
💻 Operating system
Linux
🧱 Your Environment
No response
👀 Have you spent some time to check if this issue has been raised before?
- [X] I checked and didn't find similar issue
🏢 Have you read the Code of Conduct?
- [x] I have read the Code of Conduct
Would you please update the title of this issue to be more descriptive than just "Bug Report:"?
The role:guest in the error response indicates you don't actually have an active session. Do you have multiple instances of client? Maybe you can share some of your code?
Great points by @stnguyen90 please address his questions 😇
@stnguyen90 I am getting the same exact error. I am trying to seed the data but before that created anonymous session
Here is the code
const sdk = new Appwrite();
// create anonymous session
sdk
.setEndpoint(<Endpoint>) // Your API Endpoint
.setProject('6258dbcf9d1e4227aa43') // Your project ID;
await sdk.account.createAnonymousSession();
try{
for(let i=0;i<data.results.length;i++){
const item = data.results[i]
const initSeed = {
id: uuidv4(),
title: item.title,
description: item.overview,
thumbnail_image: `https://image.tmdb.org/t/p/original/${item.poster_path}`,
popularity: item.popularity.toString(),
release_date: item.release_date,
}
// collection id and document id
const response = await sdk.database.createDocument('625926fcd8fa1d8a48fb', uuidv4(), initSeed);
console.log(response);
res.status(200).json({ data: "OK" })
}
}
catch(e){
console.log(e)
res.status(500).json({ data: "NOT OK" })
}

It would helpful to know if I am missing something here.
Error for your reference
AppwriteException: User (role: guest) missing scope (documents.write)
at Appwrite.<anonymous> (file:///Users/karthikeyan.shanmuga/.karthikeyan/movie-app-appwrite/node_modules/appwrite/dist/esm/sdk.js:2483:27)
at Generator.next (<anonymous>)
at fulfilled (file:///Users/karthikeyan.shanmuga/.karthikeyan/movie-app-appwrite/node_modules/appwrite/dist/esm/sdk.js:22:58)
at processTicksAndRejections (internal/process/task_queues.js:95:5) {
code: 401,
type: 'general_unauthorized_scope',
response: {
message: 'User (role: guest) missing scope (documents.write)',
code: 401,
type: 'general_unauthorized_scope',
version: '0.13.4'
}
}
@stnguyen90 I am getting the same exact error. I am trying to seed the data but before that created anonymous session
Here is the code
const sdk = new Appwrite(); // create anonymous session sdk .setEndpoint(<Endpoint>) // Your API Endpoint .setProject('6258dbcf9d1e4227aa43') // Your project ID; await sdk.account.createAnonymousSession(); try{ for(let i=0;i<data.results.length;i++){ const item = data.results[i] const initSeed = { id: uuidv4(), title: item.title, description: item.overview, thumbnail_image: `https://image.tmdb.org/t/p/original/${item.poster_path}`, popularity: item.popularity.toString(), release_date: item.release_date, } // collection id and document id const response = await sdk.database.createDocument('625926fcd8fa1d8a48fb', uuidv4(), initSeed); console.log(response); res.status(200).json({ data: "OK" }) } } catch(e){ console.log(e) res.status(500).json({ data: "NOT OK" }) }
It would helpful to know if I am missing something here.
@skarthikeyan96, is this server side code? If so, you should be using the node-appwrite package and an API key rather than creating an anonymous session.
it is the server side code yes. I will try that out
@stnguyen90 It actually worked after using the node-appwrite sdk. Thank you.
Would you please update the title of this issue to be more descriptive than just "Bug Report:"?
The
role:guestin the error response indicates you don't actually have an active session. Do you have multiple instances ofclient? Maybe you can share some of your code?
@sugeshthangaraj, would you please address this?
Hi,
I have the same issue, It seems that the role:guest permission doesn't span anonymous users ... I need to use role:all in order to make it work...
Hi, I have the same issue, It seems that the
role:guestpermission doesn't span anonymous users ... I need to userole:allin order to make it work...
Anonymous user is a regular Appwrite user just without any identification method (AKA email, phone, oauth).
@eldadfux the issue here is not the anonymous user, but how can I give permission to anonymous user without having to give permission with role:all... if that makes sense ... ?
@eldadfux the issue here is not the anonymous user, but how can I give permission to anonymous user without having to give permission with
role:all... if that makes sense ... ?
role:member should do the trick for all types of signed in users. Starting next version this role will be named simply: users.
Thank you @eldadfux !
Closing as this should be possible now as of 1.0 and granting any permission.