
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
- "The document data is missing. Try again...
Hello, I am getting this error suddenly. I have been using this service for a year now, and I haven't made any changes to my code since then. My app was workin...
- Error: The document data is missing. Try...
I am not able to create any document on some of the collection/ DBs. As I can see many of us facing the same issue, need a quick resolution from the Appwrite Te...
- createDocument bug
why Im getting this??? let me make it easy for you. Do you have Indexes? No. Do you have relationship attributes? No. And the funny part is that it creates the ...
