import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { tap } from 'rxjs/operators';
@Injectable({ providedIn: 'root' }) export class AuthService {
constructor( private http: HttpClient) {}
authenticate(userName : string, password: string,){
return this.http.post(API_URL + '/user/login',{userName, password}, {observe: 'response'})
.pipe(tap(res => {
const authToken = res.headers.get('x-acess-token');
window.localStorage.setItem('authToken' , authToken);
console.log(`User ${userName} authenticated with token ${authToken}`)
}))
}
}