Checkpoint: Authentication
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user