I have Angular 10 and am following a pattern like https://jasonwatmore.com/post/2020/04/19/angular-9-jwt-authentication-example-tutorial
My requirement it to make sure that I have a valid API key whenever making get requests. There are 3 cases
- Key is valid, make the api call
- Key has expired. Call a different api to get a new key first
- No key. Call the key api before calling the api
I've got the interceptor. In here I could call the key api if I don't have a current key, but how do I pause the api requests until the key is valid?
@Injectable()
export class JwtInterceptor implements HttpInterceptor {
if (!isLoggedIn) {
this.authenticationService.login().subscribe(???);
}
Where login() calls the api key generation service.
I don't want users to login, just protect the web services. What is the secret recipe?