12222
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root',
})
export class AuthService {
private apiUrl = 'http://localhost:8080/api';
constructor(private http: HttpClient) {}
login(credentials: { userId: string; password: string }): Observable<any> {
return this.http.post(${this.apiUrl}/auth/login, credentials);
}
register(userData: any): Observable<any> {
return this.http.post(${this.apiUrl}/customers/register, userData);
}
getCurrentUser(): any {
const userStr = localStorage.getItem('currentUser');
return userStr ? JSON.parse(userStr) : null;
}
// Add this method
isLoggedIn(): boolean {
return !!localStorage.getItem('currentUser');
}
logout(): void {
localStorage.removeItem('currentUser');
}
}