A
A
Alex Art2020-08-31 14:05:10
Angular
Alex Art, 2020-08-31 14:05:10

How to get response cookies in Angular interceptor?

Hello! Can you please tell me how to get the response cookies in the Angular interceptor? I write code like this

import {Injectable} from '@angular/core';
import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse} from '@angular/common/http';
import {Observable} from 'rxjs';
import {tap} from 'rxjs/operators';

@Injectable()
export class AuthInterceptor implements HttpInterceptor {
  constructor() {}

  intercept(
    req: HttpRequest<any>,
    next: HttpHandler
  ): Observable<HttpEvent<any>> {
    const authReq = req.clone({
      headers: req.headers.set('sess', '0')
    });
    return next.handle(authReq).pipe(
      tap(
        event => {
          if (event instanceof HttpResponse) {
            console.log(event.headers);
          }
        }
      )
    );
  }
}

and I only get

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gennady S, 2020-08-31
@WebmasterW3S

Angular does not work with Cookies, you will either have to work with Cookies directly, or connect a third-party solution, such as .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question