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.when calling getDocument
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" };
}
}
cookie is set
userID is also valid
if i using api key it working
i think that has simple solution
@Moderator
Recommended threads
- Websites hosted on my appwrite sites hav...
Hello, all my websites hosted on appwrite sites are not running I am getting this message "This site can’t be reached drivehub.appwrite.network took too long t...
- Session cookies stored on wrong (sub-)do...
Hi, I own a domain `example.com` which is registered with the Appwrite nameserver. My website runs on Sites, using `www.example.com` as domain, and my function...
- Function global variables
when i create a top-level global variable in go or bun how will it behave? is the heap getting renewed on every execution or could i do some kind of temp. cachi...