Flemoid (Saksham)
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) {
console Recommended threads
- Get team fail in appwrite function
I try to get team of a user inside appwrite function, but i get this error: `AppwriteException: User (role: guests) missing scope (teams.read)` If i try on cl...
- Deploy function not working - 503
Hellon i get this error message, when i try to deploy a new version of a function <html><body><h1>503 Service Unavailable</h1>No server is available to handle...
- Error When load the website
Hi, I am getting this error whenever I reload my website please help me, I am using react Error: ** GET https://cloud.appwrite.io/v1/account 401 (Unauthoriz...