Please help me to solve this error
TL;DR
Developers are getting a 401 Unauthorized error when trying to make a GET request to https://cloud.appwrite.io/v1/account. It seems like an authentication issue. Make sure the authentication process is correctly set up in the AuthService class. Also, check if the credentials are being passed correctly during login.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) {
// call another method
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 serive :: getCurrentUser :: error", error)
}
return null;
}
async logout() {
try {
await this.account.deleteSessions();
} catch (error) {
console.log("Appwrite serive :: logout :: error", error);
}
}
}
const authService = new AuthService();
export default authService
this is the error
Recommended threads
- Migration from cloud to self-hosted fail...
Hi! I'm trying to migrate a small project from the cloud to a self hosted instance to play around but without any success! The migration process fails with the ...
- Feedback and Deployment Challenges with ...
Hello world!, I've been developing a project using FastAPI in Python, and I was considering deploying it through Appwrite Functions. However, I encountered a f...
- Operators and relationships
Do operators allow modification of array of relationships?