When attempting a logout request, I have encountered an issue where the same actions need to be dispatched regardless of whether the request is successful or fails. My initial plan was to utilize the finalize()
operator for this purpose.
Unfortunately, I am struggling to get it to work as intended, as it does not seem to execute at all.
The current effect code is:
/**
* When the user logs out :
* Try to delete its push token
* Clear user
*/
logout$ = createEffect(() =>
this.actions$.pipe(
ofType(ClassicAuthActions.logout),
switchMap(action => this.api.logout().pipe(
map(() => ClassicAuthActions.logoutDidSuccess()),
catchError(err => of(ClassicAuthActions.logoutDidFail())),
finalize(() => of(
ClassicAuthActions.deleteUserCommunicationToken(),
ClassicAuthActions.clearUser(action.redirect)
)),
))
)
);
As I am relatively new to RxJS, any guidance or assistance on this matter would be highly appreciated.