
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:
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 🙏
Recommended threads
- console messaging - Error 500
Hello, on my self hosted instance (1.6.0) after I tried to use the messaging feature and press "send" for a test message, I get "Error 500" for the messaging t...
- Get current users team
Hey for one of my use cases I need to get my current logged in user's team. But by default the scope to read the team is not added. ``` const appwriteClient...
- Selfhosting problem
I'm migrating from cloud to self-hosted. I tried using 'Export to self-hosted instance' and use my free Ngrok domain as Endpoint self-hosted instance, but I got...
