From 3568017bfe1014a3a9b44effb3c591caad7d3063 Mon Sep 17 00:00:00 2001 From: Vladislav Shkodin Date: Mon, 18 Jan 2021 11:37:12 +0200 Subject: [PATCH] refactor: decouple config actions from auth actions (#4843) --- packages/netlify-cms-core/src/actions/config.js | 8 +++++--- packages/netlify-cms-core/src/bootstrap.js | 7 ++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/netlify-cms-core/src/actions/config.js b/packages/netlify-cms-core/src/actions/config.js index c10cb019..6e3bf960 100644 --- a/packages/netlify-cms-core/src/actions/config.js +++ b/packages/netlify-cms-core/src/actions/config.js @@ -2,7 +2,6 @@ import yaml from 'yaml'; import { Map, fromJS } from 'immutable'; import deepmerge from 'deepmerge'; import { trimStart, trim, get, isPlainObject, isEmpty } from 'lodash'; -import { authenticateUser } from 'Actions/auth'; import * as publishModes from 'Constants/publishModes'; import { validateConfig } from 'Constants/configSchema'; import { selectDefaultSortableFields, traverseFields } from '../reducers/collections'; @@ -404,7 +403,7 @@ export async function handleLocalBackend(originalConfig) { return mergedConfig; } -export function loadConfig(manualConfig = {}) { +export function loadConfig(manualConfig = {}, onLoad) { if (window.CMS_CONFIG) { return configLoaded(fromJS(window.CMS_CONFIG)); } @@ -429,7 +428,10 @@ export function loadConfig(manualConfig = {}) { const config = applyDefaults(normalizeConfig(fromJS(mergedConfig))); dispatch(configLoaded(config)); - dispatch(authenticateUser()); + + if (typeof onLoad === 'function') { + onLoad(); + } } catch (err) { dispatch(configFailed(err)); throw err; diff --git a/packages/netlify-cms-core/src/bootstrap.js b/packages/netlify-cms-core/src/bootstrap.js index d2099aa9..dfb4a978 100644 --- a/packages/netlify-cms-core/src/bootstrap.js +++ b/packages/netlify-cms-core/src/bootstrap.js @@ -6,6 +6,7 @@ import { ConnectedRouter } from 'connected-react-router'; import history from 'Routing/history'; import store from 'ReduxStore'; import { loadConfig } from 'Actions/config'; +import { authenticateUser } from 'Actions/auth'; import { getPhrases } from 'Lib/phrases'; import { selectLocale } from 'Reducers/config'; 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 * overwritten. */ - store.dispatch(loadConfig(config)); + store.dispatch( + loadConfig(config, function onLoad() { + store.dispatch(authenticateUser()); + }), + ); /** * Create connected root component.