I am trying to dispatch two actions in one effect. One is for user user authentication (something like isAuthenticated = true) and one for setting user (in future user data will be probably returned from rest response) so I have two separate stores one for user, one for auth. Everything is fine because actions are dispatching the problem is they are dispatched again and again which is regular behavior but after a while due to SET_USER action app is crashing. Is there any way to take value of user credentials only once and leave regular behavior for checking authentication? Here is code snippet:
@Effect()
authSignin = this.actions$
.pipe(
ofType(AuthActions.TRY_SIGNIN),
map((action: AuthActions.TrySignin) => {
console.log('AuthEffects -> authSignin');
return action.payload;
}),
switchMap((data: any) => {
this.router.navigate(['/student']);
const user: User = {
id: '1',
firstName: 'John',
lastName: 'Doe',
pesel: '19827364',
dateOfBirth: new Date(),
address: 'Canada, where clone syrup is made',
phoneNumber: '14 2345 345'
}
return [
{ type: AuthActions.TRY_SIGNIN },
{ type: UserActions.SET_USER, payload: user }
]
})
)
So the question once again: Is there any way to take value of user credentials only once and leave regular behavior for checking authentication?
Any hint would be very helpful. Thank you.