appwrite icon indicating copy to clipboard operation
appwrite copied to clipboard

🐛 Bug Report: Can't create document as anonymous user

Open sugeshthangaraj opened this issue 3 years ago • 13 comments
trafficstars

👟 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. at Generator.next () at fulfilled

🎲 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?

sugeshthangaraj avatar Mar 05 '22 08:03 sugeshthangaraj

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?

stnguyen90 avatar Mar 05 '22 22:03 stnguyen90

Great points by @stnguyen90 please address his questions 😇

Meldiron avatar Mar 07 '22 13:03 Meldiron

@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" })

  }   

image

It would helpful to know if I am missing something here.

skarthikeyan96 avatar Apr 15 '22 13:04 skarthikeyan96

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'
  }
}

skarthikeyan96 avatar Apr 15 '22 13:04 skarthikeyan96

@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" })

  }   

image

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.

stnguyen90 avatar Apr 15 '22 13:04 stnguyen90

it is the server side code yes. I will try that out

skarthikeyan96 avatar Apr 15 '22 15:04 skarthikeyan96

@stnguyen90 It actually worked after using the node-appwrite sdk. Thank you.

skarthikeyan96 avatar Apr 16 '22 12:04 skarthikeyan96

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?

@sugeshthangaraj, would you please address this?

stnguyen90 avatar May 28 '22 15:05 stnguyen90

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...

soufi avatar Aug 30 '22 21:08 soufi

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...

Anonymous user is a regular Appwrite user just without any identification method (AKA email, phone, oauth).

eldadfux avatar Aug 31 '22 07:08 eldadfux

@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 ... ?

soufi avatar Aug 31 '22 08:08 soufi

@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.

eldadfux avatar Aug 31 '22 10:08 eldadfux

Thank you @eldadfux !

soufi avatar Sep 01 '22 09:09 soufi

Closing as this should be possible now as of 1.0 and granting any permission.

stnguyen90 avatar Jan 05 '23 22:01 stnguyen90