Fix inituser flow

This commit is contained in:
Willem Dantuma
2020-07-23 09:42:44 +02:00
parent e057e463bd
commit 428353d379
2 changed files with 9 additions and 11 deletions

View File

@@ -3,8 +3,8 @@ import { Router } from '@angular/router';
import { OAuthService,UserInfo } from 'angular-oauth2-oidc';
import { Store, Action } from '@ngrx/store';
import { Effect, Actions,ofType } from '@ngrx/effects';
import { Observable , defer , of,from } from 'rxjs';
import { withLatestFrom,mergeMap,switchMap,map,catchError} from 'rxjs/operators';
import { Observable , defer , of,from,zip } from 'rxjs';
import { withLatestFrom,mergeMap,switchMap,map,catchError,first} from 'rxjs/operators';
import * as appCommonActions from '../actions/app-common.actions';
import * as appCommonReducers from '../reducers/app-common.reducer';
import { ItemService } from '../services/item.service';
@@ -50,16 +50,11 @@ export class AppCommonEffects {
@Effect()
initUser$: Observable<Action> = this.actions$.pipe(
ofType(appCommonActions.INITUSER),
withLatestFrom(this.store$.select(appCommonReducers.selectGetInitialized)),
switchMap(([action, initialized]) => {
if(!initialized) {
return this.userService$.getCurrentUser().pipe(
withLatestFrom(from(this.oauthService$.loadUserProfile())),
first(),
switchMap((action) => {
return zip(this.userService$.getCurrentUser(),from(this.oauthService$.loadUserProfile())).pipe(
switchMap(([user,userInfo]) => {return of(new appCommonActions.InitUserSuccess(user,userInfo as UserInfo))} ),
catchError(error => of(new appCommonActions.Fail(error))))
} else {
return [];
}
}
));