@Effect()
authSignin = this.actions$
.ofType(AuthActions.TRY_SIGNIN)
.pipe(
map((action: AuthActions.TrySignin) => {
return action.payload;
}),
switchMap((authData: { email: string; password: string }) => {
console.log(authData)
return this.httpClient.post('http://143.167.112.46:3001/sessions/create', authData)
}),
switchMap((token) => {
console.log(token)
const headers = new HttpHeaders().set(
'Authorization',
'bearer ' + token.id_token
);
return this.httpClient.get('http://143.167.112.46:3001/api/protected/user-info', {headers})
}),
mergeMap((token: string, user) => {
console.log(user, token)
this.router.navigate(['/']);
return [
{
type: AuthActions.SIGNIN
},
{
type: AuthActions.SET_TOKEN,
payload: token
}
];
});
);
switchMap((token) => {
console.log(token)
const headers = new HttpHeaders().set(
'Authorization',
'bearer ' + token.id_token
);
return this.httpClient.get('http://143.167.112.46:3001/api/protected/user-info', {headers}).pipe(
map(user => {
return { user, token }
})
)
}),
mergeMap({ user, token }) => {
console.log(user, token)
this.router.navigate(['/']);
return [
{
type: AuthActions.SIGNIN
},
{
type: AuthActions.SET_TOKEN,
payload: token
}
];
});
this.httpClient.get('http://143.167.112.46:3001/api/protected/user-info', {headers})
и все остальные запросы к серверу в сервис.