-export const saveApiToken = (token: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
- services.authService.saveApiToken(token);
- setAuthorizationHeader(services, token);
- dispatch(authActions.SAVE_API_TOKEN(token));
-};
+const init = (config: Config) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+ const remoteHosts = () => getState().auth.remoteHosts;
+ const token = services.authService.getApiToken();
+ let homeCluster = services.authService.getHomeCluster();
+ if (homeCluster && !config.remoteHosts[homeCluster]) {
+ homeCluster = undefined;
+ }
+ dispatch(authActions.SET_CONFIG({ config }));
+ Object.keys(remoteHosts()).forEach((remoteUuid: string) => {
+ const remoteHost = remoteHosts()[remoteUuid];
+ if (remoteUuid !== config.uuidPrefix) {
+ dispatch<any>(addRemoteConfig(remoteHost));
+ }
+ });
+ dispatch(authActions.SET_HOME_CLUSTER(config.loginCluster || homeCluster || config.uuidPrefix));