Misho
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
when calling getDocument
Misho
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
cookie is set
Misho
userID is also valid
Misho
if i using api key it working
Misho
i think that has simple solution
Misho
@Moderator
Recommended threads
- Different appwrite IDs are getting expos...
File_URL_FORMAT= https://cloud.appwrite.io/v1/storage/buckets/[BUCKET_ID]/files/[FILE_ID]/preview?project=[PROJECT_ID] I'm trying to access files in my web app...
- Invalid document structure: missing requ...
I just pick up my code that's working a week ago, and now I got this error: ``` code: 400, type: 'document_invalid_structure', response: { message: 'Inv...
- Error: User (role: guests) missing scope...
I want to send a verification code to the user and the given phone number and check it and create a session right after the user entered the secret. For me that...