Back

The current user is not authorized to perform the requested action

  • 0
  • Self Hosted
  • Auth
  • Web
Misho
21 Jul, 2024, 11:45
TypeScript
code: 401,
    type: 'user_unauthorized',
    response: {
      message: 'The current user is not authorized to perform the requested action.',
      code: 401,
      type: 'user_unauthorized',
      version: '1.5.7'
    }

I am getting this error

TL;DR
Developers encountered an authorization error while trying to perform an action with the current user. It seems that using an API key works but not through the user's cookie. Check if the user is properly authenticated and has the necessary permissions.
Misho
21 Jul, 2024, 11:45

when calling getDocument

Misho
21 Jul, 2024, 11:46
TypeScript
import { User } from "../../types";
import { createSessionClient } from "../../utils/appwrite-server";
import { envi } from "../../utils/env";

export async function getUser(userId: User["$id"]) {
  try {
    const { databases, account } = await createSessionClient();
    const a = await account.get();
    console.log({
      a,
      userId,
    });
    const user = await databases.getDocument<User>(
      envi.NEXT_PUBLIC_HOPPLA_DATABASE_ID,
      envi.NEXT_PUBLIC_USERS_COLLECTION_ID,
      userId
    );

    return { user };
  } catch (error) {
    console.log({ error });
    // @ts-ignore
    if (error?.type === "document_not_found") {
      return { error: "document_not_found" };
    }
    return { error: "An unexpected error occurred while getting user" };
  }
}
Misho
21 Jul, 2024, 11:46

cookie is set

Misho
21 Jul, 2024, 11:47

userID is also valid

Misho
21 Jul, 2024, 11:53

if i using api key it working

Misho
21 Jul, 2024, 11:53

i think that has simple solution

Misho
21 Jul, 2024, 11:59

@Moderator

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