From 4b909b13fbb6d8d72ab38700b91cf18920d72fc4 Mon Sep 17 00:00:00 2001 From: kytwb Date: Sun, 19 Dec 2021 15:43:09 +0100 Subject: Hotfix for requireAuthenticatedUser error --- src/components/layout/Sidebar.js | 141 ++++++++++----------- src/components/services/content/Services.js | 37 +----- .../settings/navigation/SettingsNavigation.js | 46 +++---- .../settings/recipes/RecipesDashboard.js | 5 - src/containers/layout/AppLayoutContainer.js | 10 ++ 5 files changed, 94 insertions(+), 145 deletions(-) (limited to 'src') diff --git a/src/components/layout/Sidebar.js b/src/components/layout/Sidebar.js index 57ba170e8..e3df9c2ea 100644 --- a/src/components/layout/Sidebar.js +++ b/src/components/layout/Sidebar.js @@ -3,12 +3,10 @@ import PropTypes from 'prop-types'; import ReactTooltip from 'react-tooltip'; import { defineMessages, injectIntl } from 'react-intl'; import { inject, observer } from 'mobx-react'; -import { Link } from 'react-router'; import { mdiCheckAll, mdiViewGrid, mdiPlusBox, - mdiLoginVariant, mdiCog, mdiBellOff, mdiBell, @@ -137,7 +135,6 @@ class Sidebar extends Component { const workspaceToggleMessage = isWorkspaceDrawerOpen ? messages.closeWorkspaceDrawer : messages.openWorkspaceDrawer; - const isLoggedIn = Boolean(localStorage.getItem('authToken')); return (
@@ -147,96 +144,86 @@ class Sidebar extends Component { disableToolTip={() => this.disableToolTip()} useVerticalStyle={stores.settings.all.app.useVerticalStyle} /> - {isLoggedIn ? ( - <> - + <> + + + {todosStore.isFeatureEnabledByUser ? ( - {todosStore.isFeatureEnabledByUser ? ( - - ) : null} + ) : null} + + + {stores.settings.all.app.lockingFeatureEnabled ? ( - - {stores.settings.all.app.lockingFeatureEnabled ? ( - - ) : null} - - ) : ( - - - - )} + ) : null} + - )}
diff --git a/src/components/settings/navigation/SettingsNavigation.js b/src/components/settings/navigation/SettingsNavigation.js index 953760fec..e8370d2ef 100644 --- a/src/components/settings/navigation/SettingsNavigation.js +++ b/src/components/settings/navigation/SettingsNavigation.js @@ -57,40 +57,34 @@ class SettingsNavigation extends Component { workspaceCount: PropTypes.number.isRequired, }; - handleLoginLogout() { - const isLoggedIn = Boolean(localStorage.getItem('authToken')); + handleLogout() { const isUsingWithoutAccount = this.props.stores.settings.app.server === LOCAL_SERVER; - if (isLoggedIn) { - // Remove current auth token - localStorage.removeItem('authToken'); + // Remove current auth token + localStorage.removeItem('authToken'); - if (isUsingWithoutAccount) { - // Reset server back to Ferdi API - this.props.actions.settings.update({ - type: 'app', - data: { - server: LIVE_FERDI_API, - }, - }); - } - this.props.stores.user.isLoggingOut = true; + if (isUsingWithoutAccount) { + // Reset server back to Ferdi API + this.props.actions.settings.update({ + type: 'app', + data: { + server: LIVE_FERDI_API, + }, + }); } + this.props.stores.user.isLoggingOut = true; this.props.stores.router.push('/auth/welcome'); - if (isLoggedIn) { - // Reload Ferdi, otherwise many settings won't sync correctly with the server - // after logging into another account - window.location.reload(); - } + // Reload Ferdi, otherwise many settings won't sync correctly with the server + // after logging into another account + window.location.reload(); } render() { const { serviceCount, workspaceCount, stores } = this.props; const { intl } = this.props; - const isLoggedIn = Boolean(localStorage.getItem('authToken')); const isUsingWithoutAccount = stores.settings.app.server === LOCAL_SERVER; const isUsingFranzServer = stores.settings.app.server === LIVE_FRANZ_API; @@ -107,7 +101,6 @@ class SettingsNavigation extends Component { to="/settings/services" className="settings-navigation__link" activeClassName="is-active" - disabled={!isLoggedIn} > {intl.formatMessage(messages.yourServices)}{' '} {serviceCount} @@ -116,7 +109,6 @@ class SettingsNavigation extends Component { to="/settings/workspaces" className="settings-navigation__link" activeClassName="is-active" - disabled={!isLoggedIn} > {intl.formatMessage(messages.yourWorkspaces)}{' '} {workspaceCount} @@ -126,7 +118,6 @@ class SettingsNavigation extends Component { to="/settings/user" className="settings-navigation__link" activeClassName="is-active" - disabled={!isLoggedIn} > {intl.formatMessage(messages.account)} @@ -136,7 +127,6 @@ class SettingsNavigation extends Component { to="/settings/team" className="settings-navigation__link" activeClassName="is-active" - disabled={!isLoggedIn} > {intl.formatMessage(messages.team)} @@ -158,11 +148,11 @@ class SettingsNavigation extends Component { diff --git a/src/components/settings/recipes/RecipesDashboard.js b/src/components/settings/recipes/RecipesDashboard.js index 0ba295369..4f19a6116 100644 --- a/src/components/settings/recipes/RecipesDashboard.js +++ b/src/components/settings/recipes/RecipesDashboard.js @@ -148,8 +148,6 @@ class RecipesDashboard extends Component { const communityRecipes = recipes.filter(r => !r.isDevRecipe); const devRecipes = recipes.filter(r => r.isDevRecipe); - const isLoggedIn = Boolean(localStorage.getItem('authToken')); - return (
@@ -240,7 +238,6 @@ class RecipesDashboard extends Component { key={recipe.id} recipe={recipe} onClick={() => - isLoggedIn && showAddServiceInterface({ recipeId: recipe.id }) } /> @@ -253,7 +250,6 @@ class RecipesDashboard extends Component { key={customWebsiteRecipe.id} recipe={customWebsiteRecipe} onClick={() => - isLoggedIn && showAddServiceInterface({ recipeId: customWebsiteRecipe.id, }) @@ -274,7 +270,6 @@ class RecipesDashboard extends Component { key={recipe.id} recipe={recipe} onClick={() => - isLoggedIn && showAddServiceInterface({ recipeId: recipe.id }) } /> diff --git a/src/containers/layout/AppLayoutContainer.js b/src/containers/layout/AppLayoutContainer.js index 536083c4f..c70144c8e 100644 --- a/src/containers/layout/AppLayoutContainer.js +++ b/src/containers/layout/AppLayoutContainer.js @@ -40,8 +40,18 @@ class AppLayoutContainer extends Component { requests, user, workspaces, + router } = this.props.stores; + /* HOTFIX for: + [mobx] Encountered an uncaught exception that was thrown by a reaction or observer component, in: 'Reaction[bound ]' TypeError: Cannot read properties of null (reading 'push') + at RouterStore.push (store.js:25) + at UserStore._requireAuthenticatedUser + */ + if (!user.isLoggedIn) { + router.push('/auth/welcome'); + } + const { setActive, handleIPCMessage, -- cgit v1.2.3-70-g09d2