MCPcopy Create free account
hub / github.com/ngrx/platform / AuthEffects

Class AuthEffects

projects/example-app/src/app/auth/effects/auth.effects.ts:16–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14
15@Injectable()
16export 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 );

Callers

nothing calls this directly

Calls 5

createEffectFunction · 0.90
ofTypeFunction · 0.90
loginMethod · 0.80
openMethod · 0.80
logoutMethod · 0.45

Tested by

no test coverage detected