есть такой класс в сайд эффектс:
import { Injectable } from "@angular/core";
import { Observable } from "rxjs";
import { Actions, Effect } from "@ngrx/effects";
import { Store } from "@ngrx/store";
import { HttpClient, HttpHeaders } from "@angular/common/http";
import { switchMap, map } from "rxjs/operators";
import * as fromRoot from "../../../store/root.reducers";
import * as LoggedUserActions from "./logged-user.actions";
@Injectable()
export class LoggedUserEffects {
// headers: any = new HttpHeaders().set(
// "Authorization",
// "bearer " + this.store.select(fromRoot.getToken)
// );
headers: any;
constructor(
private actions$: Actions,
private store: Store<fromRoot.State>,
private httpClient: HttpClient
) {
this.headers = new HttpHeaders().set(
"Authorization",
"bearer " + this.store.select(fromRoot.getToken)
);
}
@Effect()
userTransactionFetch = this.actions$
.ofType(LoggedUserActions.FETCH_USER_TRANSACTION)
.pipe(
switchMap(() => {
console.log(this.headers);
return this.httpClient.get(
"http://&&&&&&&:3001/api/protected/transactions",
this.headers
);
}),
map(transactions => {
console.log(transactions);
return {
type: LoggedUserActions.SET_USER_TRANSACTION,
payload: transactions
};
})
);
}
непроходит запрос, подозреваю что из-за того что токен передается в виде bearer [object Object]:
HttpHeaders {normalizedNames: Map(0), lazyUpdate: Array(1), headers: Map(0), lazyInit: HttpHeaders}
headers: Map(0) {}
lazyInit: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, headers: Map(0)}
lazyUpdate: Array(1)
0:
name: "Authorization"
op: "s"
value: "bearer [object Object]"
__proto__: Object
length: 1
__proto__: Array(0)
normalizedNames: Map(0) {}
__proto__: Object
Коллеги, подскажите пожалуйста как поправить