The code snippet is:
TypeScript
export async function getCurrentUser() {
try {
const currentAccount = await account.get();
if(!currentAccount) throw Error;
const currentUser = await databases.listDocuments(
appwriteConfig.databaseId,
appwriteConfig.userCollectionId,
[Query.equal('accountId', currentAccount.$id)]
);
if(!currentUser) throw Error;
return currentUser.documents[0];
} catch (error) {
console.log(error);
}
}
If I remove Query, it is not showing error. With Query, it gives error.
Need Help!!
TL;DR
Issue: Error encountered while using Query.equal() in the getCurrentUser function.
Solution: Update the code snippet as follows:
```javascript
import { Query } from 'appwrite';
export async function getCurrentUser() {
try {
const currentAccount = await account.get();
if (!currentAccount) throw Error;
const currentUser = await databases.listDocuments(
appwriteConfig.databaseId,
appwriteConfig.userCollectionId,
[new Query().equal('accountId', currentAccount.$id)]
);
if (!currentUser) throw Error;
return currentUser.documents[0];
} catch (error) {
consoleRecommended threads
- createMembership is not sending email wi...
Parameters should be correct. Account and Membership are successfully created. I have a next.js project with localhost origin allowed. I checked spam etc. i...
- Bulk delete failed with 401
- I created a transaction to bulk delete rows in a table has `done` equal `true` follow documentation. But when run, it returns 401 unauthorized error as screen...
- How to change "collection Id" to "collec...