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
- Query Appwrite
Hello, I have a question regarding Queries in Appwrite. If I have a string "YYYY-MM", how can I query the $createdAt column to match this filter?
- Different appwrite IDs are getting expos...
File_URL_FORMAT= https://cloud.appwrite.io/v1/storage/buckets/[BUCKET_ID]/files/[FILE_ID]/preview?project=[PROJECT_ID] I'm trying to access files in my web app...
- Invalid document structure: missing requ...
I just pick up my code that's working a week ago, and now I got this error: ``` code: 400, type: 'document_invalid_structure', response: { message: 'Inv...