Checkpoint: Authentication

This commit is contained in:
aditya.chandel
2025-02-15 21:43:06 -07:00
parent e1685b2bf8
commit d3627a2d3f
25 changed files with 669 additions and 60 deletions
@@ -0,0 +1,28 @@
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:7050/api/v1/auth/login';
constructor(private http: HttpClient) {}
login(credentials: { username: string; password: string }): Observable<any> {
return this.http.post(this.apiUrl, credentials);
}
saveToken(token: string): void {
localStorage.setItem('token', token);
}
getToken(): string | null {
return localStorage.getItem('token');
}
logout(): void {
localStorage.removeItem('token');
}
}