Last active
May 17, 2020 15:59
-
-
Save splincode/c01e0e3cae8019587d692ce2672e7739 to your computer and use it in GitHub Desktop.
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
@Injectable() | |
export class TokenInterceptor { | |
constructor(private authInfo: AuthState) {} | |
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { | |
if (this.authInfo.snapshot.token) { | |
req = req.clone({ | |
setHeaders: { | |
Authorization: `Bearer ${this.authInfo.snapshot.token}`, | |
}, | |
}); | |
} | |
return next.handle(req); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment