
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
- Sharing cookies
Hi, I’m using Appwrite Cloud, and I have a setup where my Appwrite backend is hosted on a subdomain (e.g., api.example.com), while my frontend (Next.js app) and...
- Custom Domain Issue
i have added a custom domain about 21 hours ago, but till now there is no SSL certificate is active on it. but if i do DNS check via https://dnschecker.org/#C...
- Flutter OAuth2 Google does not return to...
When the flow starts, the browser opens, I select an account, and it keeps showing: """ Page not found The page you're looking for doesn't exist. `general_rout...
