import { Injectable } from '@angular/core' ; import { HttpClient , HttpHeaders } from '@angular/common/http' ; import { Observable } from 'rxjs/Observable' ; import 'rxjs/add/operator/map' ; import { appConfig } from '../app.config' ; @ Injectable ( ) export class AuthenticationService { constructor ( private http ) { } login ( username , password ) { return this . http . post < any > ( appConfig . apiUrl + '/users/authenticate' , { username : username , password : password } ) . map ( user => { if ( user && user . token ) { localStorage . setItem ( 'currentUser' , JSON . stringify ( user ) ) ; } return user ; } ) ; } logout ( ) { localStorage . removeItem ( 'currentUser' ) ; } }