Skip to content
Init is coming / May 19 - 23
Back

Appwrite Error: 401 Unauthorized on getCurrentUser()

  • 0
  • Web
  • Auth
  • Storage
  • React Native
  • Self Hosted
AVPAWAR
10 May, 2025, 08:04

Hi everyone, I'm getting an error while trying to fetch the current user using Appwrite in my React project. Here's the error log:

auth.js:41 GET https://fra.cloud.appwrite.io/v1/account 401 (Unauthorized)

auth.js:43 Appwrite service :: getCurrentUser :: error AppwriteException: User (role: guests) missing scope (account)

Here’s my relevant code:

TypeScript
import conf from '../conf/conf.js';
import { Client, Account, ID } from "appwrite";

export class AuthService {
    client = new Client();
    account;

    constructor() {
        this.client
            .setEndpoint(conf.appwriteUrl)
            .setProject(conf.appwriteProjectId);
        this.account = new Account(this.client);
    }

    async createAccount({email, password, name}) {
        try {
            const userAccount = await this.account.create(ID.unique(), email, password, name);
            if (userAccount) {
                return this.login({email, password});
            } else {
                return userAccount;
            }
        } catch (error) {
            throw error;
        }
    }

    async login({email, password}) {
        try {
            return await this.account.createEmailPasswordSession(email, password);
        } catch (error) {
            throw error;
        }
    }

    async getCurrentUser() {
        try {
            return await this.account.get();
        } catch (error) {
            console.log("Appwrite service :: getCurrentUser :: error", error);
        }

        return null;
    }

    async logout() {
        try {
            await this.account.deleteSessions();
        } catch (error) {
            console.log("Appwrite service :: logout :: error", error);
        }
    }
}

const authService = new AuthService();
export default authService;
I’ve verified that conf.appwriteUrl and conf.appwriteProjectId are set correctly.

Am I missing a session or permission step before calling account.get()? Any help is appreciated!

Thanks in advance 🙏
TL;DR
Issue: Appwrite Error 401 Unauthorized on getCurrentUser() Error Log: - GET https://fra.cloud.appwrite.io/v1/account 401 (Unauthorized) - AppwriteException: User (role: guests) missing scope (account) Relevant Code: - AuthService class in a React project using Appwrite - Error occurs in getCurrentUser() method - Problem likely stems from missing session or permission Potential Solution: - Ensure the user has the necessary permissions and session setup before calling account.get()
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more