From 3071c489a7782f5e0b2e0ffff7547967d7f5fe00 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Fri, 19 Oct 2018 18:39:04 -0500 Subject: [PATCH] introduce props.credentials.authenticating helps prevent auth dupes and allows "flash" of Login component to be avoided while waiting for an authentication attempt that may succeed --- embark-ui/src/containers/AppContainer.js | 12 ++++++++++-- embark-ui/src/reducers/index.js | 10 +++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/embark-ui/src/containers/AppContainer.js b/embark-ui/src/containers/AppContainer.js index a53cb29b..f1119c21 100644 --- a/embark-ui/src/containers/AppContainer.js +++ b/embark-ui/src/containers/AppContainer.js @@ -28,6 +28,10 @@ class AppContainer extends Component { } queryStringAuthenticate() { + if (this.props.credentials.authenticating) { + return; + } + const token = this.getQueryToken(); if (!token) { @@ -46,7 +50,10 @@ class AppContainer extends Component { } requireAuthentication() { - return this.props.credentials.token && this.props.credentials.host && !this.props.credentials.authenticated; + return !this.props.credentials.authenticating && + !this.props.credentials.authenticated && + this.props.credentials.token && + this.props.credentials.host; } componentDidUpdate(){ @@ -71,7 +78,8 @@ class AppContainer extends Component { } shouldRenderLogin() { - return this.props.authenticationError || !this.props.credentials.authenticated; + return this.props.authenticationError || + !(this.props.credentials.authenticated || this.props.credentials.authenticating); } toggleTheme() { diff --git a/embark-ui/src/reducers/index.js b/embark-ui/src/reducers/index.js index a2f1da97..b65fac1a 100644 --- a/embark-ui/src/reducers/index.js +++ b/embark-ui/src/reducers/index.js @@ -200,7 +200,7 @@ function compilingContract(state = false, action) { return state; } -const DEFAULT_CREDENTIALS_STATE = {host: DEFAULT_HOST, token: '', authenticated: false}; +const DEFAULT_CREDENTIALS_STATE = {host: DEFAULT_HOST, token: '', authenticated: false, authenticating: false}; function credentials(state = DEFAULT_CREDENTIALS_STATE, action) { if (action.type === LOGOUT[SUCCESS]) { @@ -208,17 +208,21 @@ function credentials(state = DEFAULT_CREDENTIALS_STATE, action) { } if (action.type === AUTHENTICATE[FAILURE]) { - return {error: action.error, authenticated: false}; + return {error: action.error, authenticated: false, authenticating: false}; } if (action.type === AUTHENTICATE[SUCCESS]) { - return {...state, ...{authenticated: true, token: action.token, host: action.host, error: null}}; + return {...state, ...{authenticated: true, authenticating: false, token: action.token, host: action.host, error: null}}; } if (action.type === FETCH_CREDENTIALS[SUCCESS]) { return {...state, ...{token: action.token, host: action.host}}; } + if (action.type === AUTHENTICATE[REQUEST]) { + return {...state, ...{authenticating: true}}; + } + return state; }