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
- Email address must be in its canonical f...
Hello, Recently I was trying to signup with my GitHub account with appwrite account for availing the student benifits but while trying to signup I saw such erro...
- encrypt and decrypt buckets
I have a bucket where I switched from encryption to not encrypting files. I later realized that files already uploaded earlier stay encrypted. Now I have a buck...
- Unable to Create Storage After Upgrading...
We upgraded our Appwrite instance from version 1.8.0 to 1.9.0 and successfully ran the migration process. However, after the upgrade, we are no longer able to c...