Web Developer
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?