On local its works perfectly fine, but in vercel where i deployed my front its failing to create a session This is my code:
export class AuthService {
private readonly SESSION_KEY = 'user_session';
private client: Client;
private account: Account;
private isAuthenticatedSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
public isAuthenticated$: Observable<boolean> = this.isAuthenticatedSubject.asObservable();
constructor() {
this.client = new Client().setEndpoint('https://cloud.appwrite.io/v1');
this.client.setProject("PROJECT_ID");
this.account = new Account(this.client);
}
async login(email: string, password: string): Promise<void> {
try {
//setting email session
await this.account.createEmailSession(email, password);
// const privatejwt : Models.Jwt = await this.account.createJWT();
// console.log(privatejwt);
// //settign json web token
// await this.client.setJWT(privatejwt.jwt);
const sessionData = await this.account.get();
this.isAuthenticatedSubject.next(true); // Emit true when user is logged in
localStorage.setItem(this.SESSION_KEY, JSON.stringify(sessionData));
// localStorage.setItem('appwrite_jwt', privatejwt.jwt);
} catch (error) {
console.error('Login error:', error);
throw new Error('Failed to login. Please check your credentials and try again.');
}
}
What's the console logs show in your browser dev tools?
this is the console log
maybe the way i use the auth is wrong for production
Cant i use emailPassword session diractly from the cloud to appwrite ? or that i need a cloudfunction that will handle this ?
Screenshot please
No you don't need a function
Recommended threads
- Report: fetch failed
https://github.com/appwrite/appwrite/issues/10989 please assign this issue to me
- Domain Verification Failed - Fastly Conf...
I am trying to add my subdomain api.getmyself.app to my Custom Domain, but I keep getting the error: Domain 'getmyself.app' is owned by another customer I have...
- Data not loading at the frontend
My App that has been working for weeks, ain't loading anything at the frontend anymore. I thought maybe the API key expired but it's not the case. Users are log...