![](https://cdn.discordapp.com/embed/avatars/1.png)
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. ![](https://cdn.discordapp.com/embed/avatars/1.png)
when calling getDocument
![](https://cdn.discordapp.com/embed/avatars/1.png)
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" };
}
}
![](https://cdn.discordapp.com/embed/avatars/1.png)
cookie is set
![](https://cdn.discordapp.com/embed/avatars/1.png)
userID is also valid
![](https://cdn.discordapp.com/embed/avatars/1.png)
if i using api key it working
![](https://cdn.discordapp.com/embed/avatars/1.png)
i think that has simple solution
![](https://cdn.discordapp.com/embed/avatars/1.png)
@Moderator
Recommended threads
- login appwrite cli
hi, I'm trying to use appwrite cli in my terminal but since I login using my github account in the console, i dont have a password for the account, any idea of ...
- Clicksend
Hi all, Is there a way to connect Clicksend as a provider
- /v1/account/verification - 503 Service U...
Unable to send email verification, errror - SMTP disabled
![](/images/bgs/pre-footer.png)