Last active
March 8, 2020 15:40
-
-
Save pankajparkar/e7b19281b48b5febe231da4458313542 to your computer and use it in GitHub Desktop.
Implement Authentication in Angular App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { HttpClient, HttpHeaders } from '@angular/common/http'; | |
import { map } from 'rxjs/operators'; | |
@Injectable() | |
export class AppService { | |
constructor(private http: HttpClient) { } | |
getCountries() { | |
const headers = new HttpHeaders(); | |
headers.append('Authorization', `Bearer ${token}`); | |
return this.http.get('/api/country', { headers }); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { HttpClient, HttpHeaders } from '@angular/common/http'; | |
import { map } from 'rxjs/operators'; | |
@Injectable() | |
export class AuthInterceptorService { | |
constructor(private http: HttpClient) { } | |
getCountries() { | |
const headers = new HttpHeaders(); | |
headers.append('Authorization', `Bearer ${token}`); | |
return this.http.get('/api/country', { headers }); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment