Cześć.
Mam problem w sowim projekcie z wysyłanie nagłówków cookies przez Angulara 9.
Klasa dodająca do nagłówek authenticaation i cookies:
@Injectable()
export class JwtInterceptor implements HttpInterceptor {
constructor(
private authenticationService: AuthenticationServiceService,
private cookiesService: CookieService,
) {
}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const cookies = this.cookiesService.get('2fa_auth');
const currentUser = this.authenticationService.currentUserValue;
if (currentUser && currentUser.token) {
req = req.clone({
setHeaders: {
Authorization: `Bearer ${currentUser.token}`,
Cookie: `2fa_auth=${cookies};`,
}
});
}
return next.handle(req);
}
}
i mój module odpowiedzialny za podpięcie tej klasy:
providers: [
{provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true},
{provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true},
CookieService
],
Problem jest taki, że po wysłaniu zapytania nie ma w nagłówku w ogóle cookies.
Przyznam, że nie wiem gdzie robię błąd. Z góry dziękuje za wskazówkę.