
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
- iOS Sign in with Apple error: signup not...
I can’t get Sign in with Apple to work for my iOS app. I followed the instructions on https://appwrite.io/integrations/oauth-apple very closely and multiple tim...
- Appwrite database is rounding int values
Hi, i just noticed that appwrite is rounding the value 608542412536545279 to 608542412536545300 in my int array. It seems to somewhat relate to this github iss...
- URGENT: Auth Data GONE and replaced by "...
This issue appeared suddenly and without warning yesterday. My auth page is replaced by the 404 error, and I don't have access to any users. When users try to l...
