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
- TablesDB `updateRows` returns `database_...
Hi Appwrite team! I’m seeing a strange issue with TablesDB bulk row updates on a self-hosted Appwrite instance. **Environment** - Appwrite self-hosted `1.9.0` ...
- [SOLVED] Realtime Missing Channels
```js useEffect(() => { let subscription: RealtimeSubscription; async function loadChips() { try { const {rows: chi...
- Functions executed by events does not ap...
Hello, Running self-hosted Appwrite version 1.9.0 (with console 7.8.26). When functions are triggered by an event (eg. databases.\*tables.\*.rows.\*.create) doe...