Created
April 22, 2018 10:01
-
-
Save ShankarSumanth/f9ec109b37f3f8af07753656920efd98 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { AppState } from '../reducers'; | |
/* tslint:disable: no-switch-case-fall-through */ | |
import { Action } from '@ngrx/store'; | |
import { KeycloakActions, KeycloakActionTypes, LoginSuccess } from './keycloak.actions'; | |
import { KeycloakModel } from './keycloak.model'; | |
export interface KeycloakState { | |
keycloakModel: KeycloakModel; | |
checkingKeycloakStatus: boolean; | |
} | |
export const initialState: KeycloakState = { | |
keycloakModel: { | |
isLoggedIn: null, | |
id: null, | |
needsLogin: null, | |
showLoading: true | |
}, | |
checkingKeycloakStatus: false | |
}; | |
export function keycloakReducer(state = initialState, action: KeycloakActions): KeycloakState { | |
switch (action.type) { | |
case KeycloakActionTypes.IsLoggedInCheck: { | |
return { | |
...state, | |
checkingKeycloakStatus: true | |
}; | |
} | |
case KeycloakActionTypes.IsLoggedInCheckSuccess: { | |
return { | |
...state, | |
keycloakModel: { | |
...state.keycloakModel, | |
isLoggedIn: action.payload.loggedIn, | |
id: action.payload.idmId, | |
needsLogin: !action.payload.loggedIn | |
}, | |
checkingKeycloakStatus: false | |
}; | |
} | |
case KeycloakActionTypes.Login: { | |
return { | |
...state, | |
checkingKeycloakStatus: true | |
}; | |
} | |
case KeycloakActionTypes.LoginSuccess: { | |
return { | |
...state, | |
checkingKeycloakStatus: false | |
}; | |
} | |
default: { | |
return state; | |
} | |
} | |
} | |
export const selectKeycloakModel = ((state: AppState) => state.keycloak.keycloakModel); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment