
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
- API Endpoint to Verify Password.
I have 2 use cases where i need to verify a users password outside of login, e.g. Updating user account data (such as name, or prefs, or data in a users databa...
- Sites
So I developed an app using react native and using the cloud services offered by appwrite. Everything is set up but if I want to publish this website to the web...
- search collection by document ID
How to filter or search collection for a document using document ID, I can't find this item on the filter menu
