I am trying to use my auth service to obtain the user token then make http request with the token in my effect file, then send another action. But it keeps giving me this error on (action) => . I am new to effect and Angular so greatly appreciate the help!
Argument of type '(action: [Action, State]) => void' is not assignable to parameter of type '(value: [Action, State], index: number) => ObservableInput<{}>'. Type 'void' is not assignable to type 'ObservableInput<{}>'.
import { Injectable } from '@angular/core';
import { Actions, Effect, ofType } from '@ngrx/effects';
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/withLatestFrom';
import { HttpClient, HttpRequest } from '@angular/common/http';
import { Store, Action } from '@ngrx/store';
import { tap, mergeMap, map } from 'rxjs/operators';
import { Observable } from 'rxjs/Observable';
import * as PropertyActions from '../actions/property.actions';
//import { Recipe } from '../recipe.model';
import * as fromPropertyReducer from '../reducers/property.reducer';
import * as fromApp from '../store/app.reducer';
import { AuthService } from '../user/auth.service';
@Injectable()
export class PropertyEffects {
constructor(
private actions$: Actions,
private httpClient: HttpClient,
private store: Store<fromApp.AppState>,
private authService: AuthService
){}
@Effect()
sendMessage(): void {
// POST
this.actions$//.pipe(
.ofType(PropertyActions.FETCH_ALL_PROPERTIES)
.withLatestFrom(this.store.select('propertyState'))
.switchMap((action) => {
this.authService.getAuthenticatedUser().getSession((err, session) => {
if (err) {
return;
}
const req = new HttpRequest('POST', 'https://yxalbf1t6l.execute-api.us-east-1.amazonaws.com/dev/todos',
//state.properties,
{ "text": "Testing10", "checked": true, "properties": [{"c":6},{"b":7}] },
{reportProgress: true},
);
return this.httpClient.request(req)
}).pipe(
// If successful, dispatch success action with result
map(data => {
console.log(`Success ${JSON.stringify(data)}, 0, 2)`);
//return { type: PropertyActions.OPEN_ALL_PROPERTIES, payload: data }
//return { type: 'LOGIN_SUCCESS', payload: data }
return new PropertyActions.OpenAllProperties(data)
})
)
})
}
Then my second question is I want to do insert the header like in http request but using httpclient. How to do this
this.http.post('https://API_ID.execute-api.REGION.amazonaws.com/dev/compare-yourself', data, {
headers: new Headers({'Authorization': session.getIdToken().getJwtToken()})
})