Back

[SOLVED] Permission error

  • 0
  • Databases
  • React Native
  • Cloud
IamtheFuture
22 Oct, 2024, 13:42

try to write to the database, but am getting error

Error creating driver [Error: Error: AppwriteException: Permissions must be one of: (any, guests)]

TypeScript
const createDriverDoc = async (user: DriverUser, userId: string) => {
  try {
    const id = await databases.createDocument(
      DATABASE_ID,
      DRIVER_COLLECTION_ID,
      ID.unique(),
      {
        userId: userId,
        firstName: user.firstName,
        lastName: user.lastName,
        phone: user.phone,
        gender: user.gender,
        email: user.email,
        avatar: user.avatar,
        vehencleType: user.vehencleType,
      },
      [
        Permission.read(Role.any()),
        Permission.write(Role.user(userId)),
        Permission.update(Role.user(userId)),
        Permission.delete(Role.user(userId)),
      ]
    );
    return id;
  } catch (error: any) {
    throw new Error(error);
  }
};
TL;DR
The developer solved a permission error by ensuring the user was logged in first. The issue was with setting permissions for a user who is not logged in. They discussed collection permissions and provided code showing how they were initializing the appwrite client and writing to the database.
Kenny
22 Oct, 2024, 13:43

If you have write you don't need update and delete. Write is an alias for create/update/delete.

Kenny
22 Oct, 2024, 13:43

How are you initializing your appwrite client?

Kenny
22 Oct, 2024, 13:44

What are the permissions on this collection?

IamtheFuture
22 Oct, 2024, 13:46
TypeScript
import {
  Client,
  Account,
  Databases,
  Functions,
  Storage,
} from "react-native-appwrite";

export const client = new Client()
  .setEndpoint("https://cloud.appwrite.io/v1")
  .setProject("***")
  .setPlatform("***");

export const databases = new Databases(client);
export const account = new Account(client);
export const functions = new Functions(client);
export const storage = new Storage(client);
Kenny
22 Oct, 2024, 13:47

What are the permissions on your collection

IamtheFuture
22 Oct, 2024, 13:47

this is the collection permission

Kenny
22 Oct, 2024, 13:48

Do you have any relationships?

IamtheFuture
22 Oct, 2024, 13:48

no, no relationships

Kenny
22 Oct, 2024, 13:52

Is the userId you're setting permissions for, the user that is actively logged in? The error means that the user is trying to set permissions for something besides themselves

IamtheFuture
22 Oct, 2024, 13:58

thanks, I had to logged the user in first

Kenny
22 Oct, 2024, 13:59

[SOLVED] Permission error

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