I'm trying to get the user to continue where they left off by entering the login details from anywhere in the app, however, I don't have a token or refresh token, the backend uses session cookie.
Here is what I'm trying to do without success so far, using HttpInterceptor, once the response is 401 I show a modal using ngx-bootstrap modal service.
The above part relatively works, now I'm not sure how can get the service/intercept to request the same request that failed.
I tried to do the same thing without the interceptor without luck.
Any ideas or example would be great.
Update:
I still can't get it to work retryWhen didn't help
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(req).pipe(
retryWhen(errors =>
errors.pipe(
tap(errorStatus => {
let OrgReq;
console.log("tap: ", errorStatus);
if (errorStatus.status === 401) {
OrgReq = req.clone();
this.authModalRef = this.modalService.show(AuthenticationComponent, this.initialState);
this.authModalRef.content.onLoggedIn.subscribe(loggedIn => {
console.log("has logged? ", loggedIn, OrgReq);
return next.handle(OrgReq);
});
}
throw errorStatus;
})
)
)
);
}
I think because the first request getting unsubscribed after the 401 the next.handle() isn't doing anything