source: trip-planner-front/src/app/auth/auth.interceptor.ts

Last change on this file was 84d0fbb, checked in by Ema <ema_spirova@…>, 3 years ago

spring security 2.0

  • Property mode set to 100644
File size: 560 bytes
Line 
1import { HttpHandler, HttpHeaders, HttpInterceptor, HttpRequest } from "@angular/common/http";
2import { Injectable } from "@angular/core";
3
4@Injectable({
5 providedIn: "root"
6})
7export class AuthInterceptor implements HttpInterceptor {
8
9 constructor() { }
10
11 intercept(req: HttpRequest<any>, next: HttpHandler) {
12
13 if (sessionStorage.getItem('username') && sessionStorage.getItem('token')) {
14 req = req.clone({
15 headers: req.headers.set("Authorization", "" + sessionStorage.getItem("token"))
16 });
17 }
18
19 return next.handle(req);
20
21 }
22}
Note: See TracBrowser for help on using the repository browser.