Jayant
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. Jayant
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
Jayant
this is the error
Recommended threads
- Creating nested relation on a two-way ma...
The example provided in the docs here has an example of what looks like a one to many (by passing a nested array of documents) https://appwrite.io/docs/produ...
- AppwriteException: Collection with the r...
Note: **It's working on local but not in production / vercel on for this page** Hello, I am facing collection ID issue. I have done the similar way in my other...
- Email verification in android applicatio...
i am creating email verification inside my android app. in the docs it asks for redirect email. i am currently using appwrite cloud. what am i supposed to do? ...