Skip to content

Instantly share code, notes, and snippets.

@ShankarSumanth
Created April 22, 2018 10:01
Show Gist options
  • Save ShankarSumanth/f9ec109b37f3f8af07753656920efd98 to your computer and use it in GitHub Desktop.
Save ShankarSumanth/f9ec109b37f3f8af07753656920efd98 to your computer and use it in GitHub Desktop.
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