refactor: decouple config actions from auth actions (#4843)

This commit is contained in:
Vladislav Shkodin 2021-01-18 11:37:12 +02:00 committed by GitHub
parent bed71274cb
commit 3568017bfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -2,7 +2,6 @@ import yaml from 'yaml';
import { Map, fromJS } from 'immutable'; import { Map, fromJS } from 'immutable';
import deepmerge from 'deepmerge'; import deepmerge from 'deepmerge';
import { trimStart, trim, get, isPlainObject, isEmpty } from 'lodash'; import { trimStart, trim, get, isPlainObject, isEmpty } from 'lodash';
import { authenticateUser } from 'Actions/auth';
import * as publishModes from 'Constants/publishModes'; import * as publishModes from 'Constants/publishModes';
import { validateConfig } from 'Constants/configSchema'; import { validateConfig } from 'Constants/configSchema';
import { selectDefaultSortableFields, traverseFields } from '../reducers/collections'; import { selectDefaultSortableFields, traverseFields } from '../reducers/collections';
@ -404,7 +403,7 @@ export async function handleLocalBackend(originalConfig) {
return mergedConfig; return mergedConfig;
} }
export function loadConfig(manualConfig = {}) { export function loadConfig(manualConfig = {}, onLoad) {
if (window.CMS_CONFIG) { if (window.CMS_CONFIG) {
return configLoaded(fromJS(window.CMS_CONFIG)); return configLoaded(fromJS(window.CMS_CONFIG));
} }
@ -429,7 +428,10 @@ export function loadConfig(manualConfig = {}) {
const config = applyDefaults(normalizeConfig(fromJS(mergedConfig))); const config = applyDefaults(normalizeConfig(fromJS(mergedConfig)));
dispatch(configLoaded(config)); dispatch(configLoaded(config));
dispatch(authenticateUser());
if (typeof onLoad === 'function') {
onLoad();
}
} catch (err) { } catch (err) {
dispatch(configFailed(err)); dispatch(configFailed(err));
throw err; throw err;

View File

@ -6,6 +6,7 @@ import { ConnectedRouter } from 'connected-react-router';
import history from 'Routing/history'; import history from 'Routing/history';
import store from 'ReduxStore'; import store from 'ReduxStore';
import { loadConfig } from 'Actions/config'; import { loadConfig } from 'Actions/config';
import { authenticateUser } from 'Actions/auth';
import { getPhrases } from 'Lib/phrases'; import { getPhrases } from 'Lib/phrases';
import { selectLocale } from 'Reducers/config'; import { selectLocale } from 'Reducers/config';
import { I18n } from 'react-polyglot'; import { I18n } from 'react-polyglot';
@ -72,7 +73,11 @@ function bootstrap(opts = {}) {
* config.yml if it exists, and any portion that produces a conflict will be * config.yml if it exists, and any portion that produces a conflict will be
* overwritten. * overwritten.
*/ */
store.dispatch(loadConfig(config)); store.dispatch(
loadConfig(config, function onLoad() {
store.dispatch(authenticateUser());
}),
);
/** /**
* Create connected root component. * Create connected root component.