
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
- Domain not working
My domain [fork-fable.appwrite.network](https://fork-fable.appwrite.network/) returns a 500 even after deleting and redeploying. Other domains added in domains ...
- File tokens regenerate each page reload
Hello, on appwrite 1.7.4, when I create a file token via the API Tokens(appwriteAdminClient)#createFileToken I get a secret, then when I check in the console t...
- CSV Import Shows Success but Data Not Ap...
I tried importing a CSV file into my PRODUCTS collection. The dashboard shows the message “Import to PRODUCTS completed successfully,” but no data appears in th...
