
I'm struggling the get the current logged user using the method Account.get().
my code:
export async function getCurrentUser(){
try{
const currentUser = await account.get();
if(!currentUser) return null;
const user = await databases.listDocuments(
appwriteConfig.database,
appwriteConfig.usersDB,
[
Query.equal('accountId', currentUser.$id)
]
);
if(!user) throw Error("Usuario logado nao encontrado.");
return user.documents[0];
}catch(error){
console.log(error)
throw Error("Erro ao carregar o usuario logado.")
}
}
Its always returning the error:
code: 401,
type: 'general_unauthorized_scope',
response: {
message: 'User (role: guests) missing scope (account)',
code: 401,
type: 'general_unauthorized_scope',
version: '0.12.21'
}
How do I solve this?

Is this client-side code ? If yes, how have you instantiated the appwrite client ? Can you show please ?

Opps! I was running the code on server-side. Thats was the error. thanks for your help

[SOLVED] Error getting the current logged user
Recommended threads
- Need help setting up this error is showi...
You can't sign in to this app because it doesn't comply with Google's OAuth 2.0 policy. If you're the app developer, register the redirect URI in the Google Cl...
- Appwrite stopped working, I can't authen...
I'm having an issue with Appwrite. It was working fine just a while ago, but suddenly it stopped working for me and can't authenticate accounts. I even went bac...
- Fail to receive the verification email a...
I added my email address to prevent it from showing "appwrite," but now I'm not receiving emails for verification or password resets. The function appears to be...
