Skip to content

Instantly share code, notes, and snippets.

@pankajparkar
Last active March 8, 2020 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pankajparkar/e7b19281b48b5febe231da4458313542 to your computer and use it in GitHub Desktop.
Save pankajparkar/e7b19281b48b5febe231da4458313542 to your computer and use it in GitHub Desktop.
Implement Authentication in Angular App
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 });
}
}
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