Last active
May 17, 2020 07:39
-
-
Save splincode/ccdae12f1b9fc85b1f5e2db3aa7ce80c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 store: Store) {} | |
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { | |
const token: string | null = this.store.selectSnapshot(AuthState.token); | |
if (token) { | |
req = req.clone({ | |
setHeaders: { | |
Authorization: `Bearer ${token}`, | |
}, | |
}); | |
} | |
return next.handle(req); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment