Hey im having some troubles with getting the currentUser. I managed to get the Account with account.get but when i want to do this to get the currentUser the object in console is null
export const getAccount = async () => { try { const currentAccount = await account.get(); console.log(currentAccount); return currentAccount; } catch (error) { throw new Error(error); } }
export const getCurrentUser = async () => { try { const currentAccount = await getAccount(); if (!currentAccount) throw new Error('Account not found');
const currentUser = await databases.listDocuments(
appwriteConfig.databaseId,
appwriteConfig.userCollectionId,
[Query.equal('id', currentAccount.$id)] // Ensure 'accountId' exists in the schema
);
console.log(currentUser)
if (!currentUser) throw new Error('User not found');
return currentUser.documents[0];
} catch (error) {
console.log(error);
return null;
}
} can someone maybe help?
message: "Invalid query: Attribute not found in schema: id" this is the error message in devtools
i tried with accountid aswell but doesnt work
Do you have added a collection with an attribute called id? If you want to get a single document by it's ID, use database.getDocument() instead of listDocuments()
ok tried it with get.Document() but now i get invalid documentID error
Do you have a collection and a document with that id?
Is there any document being shown in the console?
i get the whole account object in console with an id attribute
i dont really knwo what u mean by collection and document. I just read on the docs that this is how to get the currentUser for the session but thats not working xD
Recommended threads
- DB Relational Table Request
Hi, I'd like to suggest a rewording of the relationships between tables. - Current wording: storeOperatingDays can contain one storeId ...
- Domain is already used. Please try again...
I have a website with where the www.domain.me This website works just fine But if I try to visit domain.me. I get this error. I keep getting sent to some app ri...
- Redirect from clicking team invite link ...
Hi all! Pretty new to app development in general so this might be something more generic than appwrite, but I've found (after reading the docs for the Teams API...