Back

[SOLVED] User (role: guests) missing scope (users.write)

  • 1
  • Web
  • Cloud
K_Vasen
3 Dec, 2023, 07:30

I am trying to explore the node sdk for appwrite. I couldn't able to create user. Whenever I try to create user or to write in db. I am getting this error User (role: guests).

TypeScript
import * as env from "dotenv";
import {
  Client,
  Users,
  Account,
  Databases,
  ID,
  Permission,
  Role,
} from "node-appwrite";

env.config();

const client = new Client();
client
  .setEndpoint("https://cloud.appwrite.io/v1")
  .setProject(process.env.PROJECT_ID)
  .setKey(process.env.API_KEY).setSelfSigned(true);

const users = new Users(client);

const dbs = new Databases(client);

async function createDB(){
    return await dbs.create(ID.unique(), "Demo Database");
}

async function createUser(email, password, name){
    return await users.create(ID.unique(), email, undefined, password, name);
}

This is my code

TL;DR
User is getting the error "User (role: guests)" when trying to create a user or write to the database using the Appwrite Node.js SDK. The error indicates that the user is not authenticated. The user has checked if the project ID and API key were correct, but the issue persisted. Someone recommended debugging `process.env.PROJECT_ID` and `process.env.API_KEY`. The user mentioned that they had successfully used the Python SDK. Solution: In the code provided, the user has not called the `users.createSession()` function after setting the project ID and API key. This function is necessary to authenticate the user.
K_Vasen
3 Dec, 2023, 08:34

I have done the same thing in python sdk I worked perfectly fine!!

WhiteWalker72
3 Dec, 2023, 08:53

Did you debug process.env.PROJECT_ID and process.env.API_KEY already?

K_Vasen
3 Dec, 2023, 11:46

I have tried by giving the key as a string directly... Even It didn't works!!

Drake
3 Dec, 2023, 14:39

The guests error means you're not authenticated. So, either the project id or API key is incorrect

K_Vasen
3 Dec, 2023, 19:04

Yes.. Either of them was incorrect.. My bad

Drake
4 Dec, 2023, 07:03

[SOLVED] User (role: guests) missing scope (users.write)

Drake
4 Dec, 2023, 07:03

No worries! Glad you figured it out!

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more