-
-
Save gdyrrahitis/9441bf83b0ea193246f69462ea5b6b2d 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 AuthInterceptor implements HttpInterceptor { | |
constructor(private authService: AuthService) { } | |
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { | |
if (this.authService.isAuthenticated()) { | |
const accessToken = JSON.parse(this.authService.getToken()).access_token; | |
const token = `Bearer ${accessToken}`; | |
const authReq = req.clone({ headers: req.headers.set("Authorization", token) }); | |
return next.handle(authReq) as any; | |
} | |
return next.handle(req) as any; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment