import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { map } from 'rxjs/operators'; import { Constant } from './constant.enum'; import { Observable } from "rxjs"; @Injectable({ providedIn: 'root' }) export class AuthService { public _username; //private headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' }); constructor(private http: HttpClient) {} //private postheaders = new Headers({'Content-Type': 'application/json'}); login(username: string, password: string) : Observable { this._username = username; return this.http.post(Constant.APPSERVICEURL + "/login", { username, password }) .pipe(map(user => { // login successful if there's a jwt token in the response if (user && user.token) { // store user details and jwt token in local storage to keep user logged in between page refreshes localStorage.setItem('TokenInfo', JSON.stringify(user)); } return user; })); } logout() { localStorage.removeItem('TokenInfo'); } public GetMenu(): Observable { return this.http.get(Constant.APPSERVICEURL +'/Menus/userMenus?username='+ this._username) .pipe(map(res => { return res; })); } }