1
1
import { Injector } from '@angular/core' ;
2
+ import { Router } from '@angular/router' ;
2
3
import { Store } from '@ngxs/store' ;
3
4
import { AuthConfig , OAuthService } from 'angular-oauth2-oidc' ;
4
- import { ConfigState } from '../states/config.state' ;
5
- import { CORE_OPTIONS } from '../tokens/options.token' ;
6
- import { Router } from '@angular/router' ;
7
5
import { Observable , of } from 'rxjs' ;
8
- import { RestService } from '../services/rest.service' ;
9
- import { switchMap } from 'rxjs/operators' ;
6
+ import { switchMap , tap } from 'rxjs/operators' ;
10
7
import { GetAppConfiguration } from '../actions/config.actions' ;
8
+ import { RestOccurError } from '../actions/rest.actions' ;
9
+ import { RestService } from '../services/rest.service' ;
10
+ import { ConfigState } from '../states/config.state' ;
11
11
12
12
export abstract class AuthFlowStrategy {
13
13
abstract readonly isInternalAuth : boolean ;
14
14
15
+ protected store : Store ;
15
16
protected oAuthService : OAuthService ;
16
17
protected oAuthConfig : AuthConfig ;
17
18
abstract checkIfInternalAuth ( ) : boolean ;
18
19
abstract login ( ) : void ;
19
20
abstract logout ( ) : Observable < any > ;
20
21
abstract destroy ( ) : void ;
21
22
22
- private catchError = err => {
23
- // TODO: handle the error
24
- } ;
23
+ private catchError = err => this . store . dispatch ( new RestOccurError ( err ) ) ;
25
24
26
25
constructor ( protected injector : Injector ) {
26
+ this . store = injector . get ( Store ) ;
27
27
this . oAuthService = injector . get ( OAuthService ) ;
28
28
this . oAuthConfig = injector . get ( Store ) . selectSnapshot ( ConfigState . getDeep ( 'environment.oAuthConfig' ) ) ;
29
29
}
@@ -74,10 +74,9 @@ export class AuthPasswordFlowStrategy extends AuthFlowStrategy {
74
74
}
75
75
76
76
logout ( ) {
77
- const store = this . injector . get ( Store ) ;
78
77
const rest = this . injector . get ( RestService ) ;
79
78
80
- const issuer = store . selectSnapshot ( ConfigState . getDeep ( 'environment.oAuthConfig.issuer' ) ) ;
79
+ const issuer = this . store . selectSnapshot ( ConfigState . getDeep ( 'environment.oAuthConfig.issuer' ) ) ;
81
80
return rest
82
81
. request (
83
82
{
@@ -88,10 +87,8 @@ export class AuthPasswordFlowStrategy extends AuthFlowStrategy {
88
87
issuer ,
89
88
)
90
89
. pipe (
91
- switchMap ( ( ) => {
92
- this . oAuthService . logOut ( ) ;
93
- return store . dispatch ( new GetAppConfiguration ( ) ) ;
94
- } ) ,
90
+ tap ( ( ) => this . oAuthService . logOut ( ) ) ,
91
+ switchMap ( ( ) => this . store . dispatch ( new GetAppConfiguration ( ) ) ) ,
95
92
) ;
96
93
}
97
94
0 commit comments