| 14 | |
| 15 | @Injectable() |
| 16 | export class AuthEffects { |
| 17 | login$ = createEffect(() => |
| 18 | this.actions$.pipe( |
| 19 | ofType(LoginPageActions.login), |
| 20 | map((action) => action.credentials), |
| 21 | exhaustMap((auth: Credentials) => |
| 22 | this.authService.login(auth).pipe( |
| 23 | map((user) => AuthApiActions.loginSuccess({ user })), |
| 24 | catchError((error) => of(AuthApiActions.loginFailure({ error }))) |
| 25 | ) |
| 26 | ) |
| 27 | ) |
| 28 | ); |
| 29 | |
| 30 | loginSuccess$ = createEffect( |
| 31 | () => |
| 32 | this.actions$.pipe( |
| 33 | ofType(AuthApiActions.loginSuccess), |
| 34 | tap(() => this.router.navigate(['/'])) |
| 35 | ), |
| 36 | { dispatch: false } |
| 37 | ); |
| 38 | |
| 39 | loginRedirect$ = createEffect( |
| 40 | () => |
| 41 | this.actions$.pipe( |
| 42 | ofType(AuthApiActions.loginRedirect, AuthActions.logout), |
| 43 | tap(() => { |
| 44 | this.router.navigate(['/login']); |
| 45 | }) |
| 46 | ), |
| 47 | { dispatch: false } |
| 48 | ); |
| 49 | |
| 50 | logoutConfirmation$ = createEffect(() => |
| 51 | this.actions$.pipe( |
| 52 | ofType(AuthActions.logoutConfirmation), |
| 53 | exhaustMap(() => { |
| 54 | const dialogRef = this.dialog.open< |
| 55 | LogoutConfirmationDialogComponent, |
| 56 | undefined, |
| 57 | boolean |
| 58 | >(LogoutConfirmationDialogComponent); |
| 59 | |
| 60 | return dialogRef.afterClosed(); |
| 61 | }), |
| 62 | map((result) => |
| 63 | result ? AuthActions.logout() : AuthActions.logoutConfirmationDismiss() |
| 64 | ) |
| 65 | ) |
| 66 | ); |
| 67 | |
| 68 | logoutIdleUser$ = createEffect(() => |
| 69 | this.actions$.pipe( |
| 70 | ofType(UserActions.idleTimeout), |
| 71 | map(() => AuthActions.logout()) |
| 72 | ) |
| 73 | ); |
nothing calls this directly
no test coverage detected