import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { map } from 'rxjs/operators';
import { environment } from '../../environments/environment';
@Injectable()
export class AuthenticationService {
constructor(private http: HttpClient) { }
login(username: string, password: string) {
const headers = new Headers();
headers.append('Content-Type','application/json');
headers.append('appkey','123');
return this.http.post<any>(`${environment.apiUrl}/login`, { user: username, pass: password }, { headers: headers})
.pipe(map(data => {
// login successful if there's a jwt token in the response
if (data && data.sessionID) {
// store user details and jwt token in local storage to keep user logged in between page refreshes
localStorage.setItem('currentUser', JSON.stringify(data));
}
return data;
}));
}
logout() {
// remove user from local storage to log user out
localStorage.removeItem('data');
}
}
Argument of type '{ headers: Headers; }' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: Ht...'.
Types of property 'headers' are incompatible.
Type 'Headers' is not assignable to type 'HttpHeaders | { [header: string]: string | string[]; }'.
Type 'Headers' is not assignable to type '{ [header: string]: string | string[]; }'.
Index signature is missing in type 'Headers'.
import { HttpClient, HttpHeaders } from '@angular/common/http';
const headers = new Headers();