#[SOLVED] Error getting the current logged user

3 messages · Page 1 of 1 (latest)

severe kayak
#

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?

magic pollen
#

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

severe kayak
#

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