1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Trying to repeat a http request after refresh token with a interceptor in angular 7

Discussão em 'Angular' iniciado por user10955671, Outubro 16, 2024 às 09:02.

  1. user10955671

    user10955671 Guest

    I'm trying to automate the refresh token requests upon receiving an error 401 with angular 7.

    Between that I do not find much documentation of how to do it with angular 7 and that I do not have previous knowledge of angular or rxjs I am becoming a little crazy

    I think it's almost completed, but for some reason the second next.handle(newReq) dont send the request (in google chrome network debugger only apears first request)

    i'm gettin the response of refresh and making processLoginResponse(res) correctly

    you can see here my interceptor

    intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {

    let newReq = req.clone();

    return next.handle(req).pipe(
    catchError(error => {
    if (error.status == 401) {
    this._authenticationService.refresh().subscribe(
    res => {
    this._authenticationService.processLoginResponse(res);
    newReq.headers.set("Authorization", "Bearer " + this._authenticationService.authResponse.token)
    return next.handle(newReq)
    },
    error => {
    this._authenticationService.logOut();
    });
    }
    throw error;
    })
    );

    Continue reading...

Compartilhe esta Página