File tree 1 file changed +14
-11
lines changed
1 file changed +14
-11
lines changed Original file line number Diff line number Diff line change 1
1
import { Injectable } from '@angular/core' ;
2
- import { Actions , createEffect } from '@ngrx/effects' ;
2
+ import { Actions , createEffect , ofType } from '@ngrx/effects' ;
3
+ import { AuthActions } from './action-types' ;
4
+ import { tap } from 'rxjs/operators' ;
3
5
4
6
5
7
@Injectable ( )
6
8
export class AuthEffects {
7
9
8
- constructor ( private actions$ : Actions ) {
9
-
10
- actions$ . subscribe ( action => {
11
-
12
- if ( action . type == '[Login Page] User Login' ) {
10
+ login$ = createEffect ( ( ) =>
11
+ this . actions$
12
+ . pipe (
13
+ ofType ( AuthActions . login ) ,
14
+ tap ( action => localStorage . setItem ( 'user' ,
15
+ JSON . stringify ( action . user ) )
16
+ )
17
+ )
18
+ ,
19
+ { dispatch : false } ) ;
13
20
14
- localStorage . setItem ( 'user' ,
15
- JSON . stringify ( action [ "user" ] ) ) ;
16
- }
17
21
18
-
19
- } ) ;
22
+ constructor ( private actions$ : Actions ) {
20
23
21
24
}
22
25
You can’t perform that action at this time.
0 commit comments