import { Injectable } from '@angular/core' ; import { Store } from '@ngrx/store' ; import { Observable } from 'rxjs' ; import { AppStoreService } from '@app/@store/app.store.service' ; import { AppState } from '@app/@store/app.state' ; import * as auth from './auth.actions' ; import { IAuthState } from './auth.reducer' ; import { ICurrentUserState } from './currentUser.reducer' ; import { map } from 'rxjs/operators' ; @ Injectable ( ) export class AuthStoreService extends AppStoreService { protected STATE = 'currentUser' ; constructor ( protected store ) { super ( ) ; } dispatchCheckAuthAction ( ) { this . dispatchAction ( new auth . CheckAuthAction ( ) ) ; } dispatchLoginAction ( record ) { this . dispatchAction ( new auth . LoginAction ( record ) ) ; } dispatchLogoutAction ( ) { this . dispatchAction ( new auth . LogoutAction ( ) ) ; } dispatchCreateAction ( record ) { this . dispatchAction ( new auth . CreateAction ( record ) ) ; } dispatchTokenSaveAction ( ) { this . dispatchAction ( new auth . TokenSaveAction ( ) ) ; } dispatchTokenDeleteAction ( ) { this . dispatchAction ( new auth . TokenDeleteAction ( ) ) ; } dispatchLoadAction ( params ) { } dispatchUpdateAction ( record ) { } dispatchRemoveAction ( id ) { } getCurrentUser ( ) { this . STATE = 'currentUser' ; return this . storeSelectFeatureState ( ) . pipe ( map ( ( state ) => state ) ) ; } getAuthCheck ( ) { this . STATE = 'authCheck' ; return this . storeSelectFeatureState ( ) . pipe ( map ( ( state ) => { return state ; } ) ) ; } isAuthenticated ( ) { let isAuthenticated = false ; this . getAuthCheck ( ) . subscribe ( isAuth => isAuthenticated = isAuth ) ; return isAuthenticated ; } }