From fe1a0a6f3b4c6d0fb5dcdf1ad33c32b35fbd7125 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Thu, 18 Oct 2018 15:36:15 -0500 Subject: [PATCH 01/24] only auth w/ stored token if there is no query string token --- embark-ui/src/containers/AppContainer.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/embark-ui/src/containers/AppContainer.js b/embark-ui/src/containers/AppContainer.js index 593699c41..d5606701b 100644 --- a/embark-ui/src/containers/AppContainer.js +++ b/embark-ui/src/containers/AppContainer.js @@ -25,8 +25,6 @@ const qs = require('qs'); class AppContainer extends Component { constructor (props) { super(props); - - this.queryStringAuthenticate(); } queryStringAuthenticate() { @@ -39,7 +37,7 @@ class AppContainer extends Component { if (token === this.props.credentials.token && this.props.credentials.host === host) { return; } - this.props.authenticate(host, token); + return this.props.authenticate(host, token); } componentDidMount() { @@ -53,7 +51,9 @@ class AppContainer extends Component { componentDidUpdate(){ if (this.requireAuthentication()) { - this.props.authenticate(this.props.credentials.host, this.props.credentials.token); + if (!this.queryStringAuthenticate()) { + this.props.authenticate(this.props.credentials.host, this.props.credentials.token); + } } if (this.props.credentials.authenticated && !this.props.initialized) { From 2432489943f44087bce7a91a31cc8b8fc69de94a Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Fri, 19 Oct 2018 11:57:33 -0500 Subject: [PATCH 02/24] remove useless constructor --- embark-ui/src/containers/AppContainer.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/embark-ui/src/containers/AppContainer.js b/embark-ui/src/containers/AppContainer.js index d5606701b..88e499c1d 100644 --- a/embark-ui/src/containers/AppContainer.js +++ b/embark-ui/src/containers/AppContainer.js @@ -23,10 +23,6 @@ import { getCredentials, getAuthenticationError, getProcesses, getTheme } from ' const qs = require('qs'); class AppContainer extends Component { - constructor (props) { - super(props); - } - queryStringAuthenticate() { const token = qs.parse(this.props.location.search, {ignoreQueryPrefix: true}).token; From 1b20bbbeb88f8ca1b87bb5bd32913897f0133476 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Fri, 19 Oct 2018 16:55:54 -0500 Subject: [PATCH 03/24] invoke queryStringAuthenticate before requireAuthentication --- embark-ui/src/containers/AppContainer.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/embark-ui/src/containers/AppContainer.js b/embark-ui/src/containers/AppContainer.js index 88e499c1d..314684a0e 100644 --- a/embark-ui/src/containers/AppContainer.js +++ b/embark-ui/src/containers/AppContainer.js @@ -46,10 +46,8 @@ class AppContainer extends Component { } componentDidUpdate(){ - if (this.requireAuthentication()) { - if (!this.queryStringAuthenticate()) { - this.props.authenticate(this.props.credentials.host, this.props.credentials.token); - } + if (!this.queryStringAuthenticate() && this.requireAuthentication()) { + this.props.authenticate(this.props.credentials.host, this.props.credentials.token); } if (this.props.credentials.authenticated && !this.props.initialized) { From 2abcfe5de0c1ae6a7a656e6bd87dda963908c51b Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Fri, 19 Oct 2018 14:35:33 -0500 Subject: [PATCH 04/24] remove token from URL and replace location in history if auth'd --- embark-ui/src/containers/AppContainer.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/embark-ui/src/containers/AppContainer.js b/embark-ui/src/containers/AppContainer.js index 314684a0e..e47ca54b2 100644 --- a/embark-ui/src/containers/AppContainer.js +++ b/embark-ui/src/containers/AppContainer.js @@ -23,8 +23,12 @@ import { getCredentials, getAuthenticationError, getProcesses, getTheme } from ' const qs = require('qs'); class AppContainer extends Component { + getToken() { + return qs.parse(this.props.location.search, {ignoreQueryPrefix: true}).token; + } + queryStringAuthenticate() { - const token = qs.parse(this.props.location.search, {ignoreQueryPrefix: true}).token; + const token = this.getToken(); if (!token) { return; @@ -50,6 +54,15 @@ class AppContainer extends Component { this.props.authenticate(this.props.credentials.host, this.props.credentials.token); } + if (this.getToken() && this.props.credentials.authenticated) { + const loc = Object.assign({}, this.props.location); + loc.search = loc.search.replace( + /(\?|&?)(token=[\w-]*)(&?)/, + (_, p1, p2, p3) => (p2 ? (p3 === '&' ? p1 : '') : '') + ); + this.props.history.replace(loc); + } + if (this.props.credentials.authenticated && !this.props.initialized) { this.props.fetchProcesses(); this.props.fetchServices(); From ee13fcf3adacd1a79a3dab21e3caf187f72be3a4 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Fri, 19 Oct 2018 14:39:42 -0500 Subject: [PATCH 05/24] getToken -> getQueryToken --- embark-ui/src/containers/AppContainer.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/embark-ui/src/containers/AppContainer.js b/embark-ui/src/containers/AppContainer.js index e47ca54b2..a53cb29b5 100644 --- a/embark-ui/src/containers/AppContainer.js +++ b/embark-ui/src/containers/AppContainer.js @@ -23,12 +23,12 @@ import { getCredentials, getAuthenticationError, getProcesses, getTheme } from ' const qs = require('qs'); class AppContainer extends Component { - getToken() { + getQueryToken() { return qs.parse(this.props.location.search, {ignoreQueryPrefix: true}).token; } queryStringAuthenticate() { - const token = this.getToken(); + const token = this.getQueryToken(); if (!token) { return; @@ -54,7 +54,7 @@ class AppContainer extends Component { this.props.authenticate(this.props.credentials.host, this.props.credentials.token); } - if (this.getToken() && this.props.credentials.authenticated) { + if (this.getQueryToken() && this.props.credentials.authenticated) { const loc = Object.assign({}, this.props.location); loc.search = loc.search.replace( /(\?|&?)(token=[\w-]*)(&?)/, From 3071c489a7782f5e0b2e0ffff7547967d7f5fe00 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Fri, 19 Oct 2018 18:39:04 -0500 Subject: [PATCH 06/24] 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 a53cb29b5..f1119c21d 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 a2f1da97d..b65fac1a4 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; } From d02d2f1522a30a5281822501e5a75db2e647201f Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Fri, 19 Oct 2018 18:40:56 -0500 Subject: [PATCH 07/24] make token stripping logic reusable --- embark-ui/src/containers/AppContainer.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/embark-ui/src/containers/AppContainer.js b/embark-ui/src/containers/AppContainer.js index f1119c21d..cfb7793d7 100644 --- a/embark-ui/src/containers/AppContainer.js +++ b/embark-ui/src/containers/AppContainer.js @@ -27,6 +27,15 @@ class AppContainer extends Component { return qs.parse(this.props.location.search, {ignoreQueryPrefix: true}).token; } + stripQueryToken(location) { + const _location = Object.assign({}, location); + _location.search = _location.search.replace( + /(\?|&?)(token=[\w-]*)(&?)/, + (_, p1, p2, p3) => (p2 ? (p3 === '&' ? p1 : '') : '') + ); + return _location; + } + queryStringAuthenticate() { if (this.props.credentials.authenticating) { return; @@ -62,12 +71,7 @@ class AppContainer extends Component { } if (this.getQueryToken() && this.props.credentials.authenticated) { - const loc = Object.assign({}, this.props.location); - loc.search = loc.search.replace( - /(\?|&?)(token=[\w-]*)(&?)/, - (_, p1, p2, p3) => (p2 ? (p3 === '&' ? p1 : '') : '') - ); - this.props.history.replace(loc); + this.props.history.replace(this.stripQueryToken(this.props.location)); } if (this.props.credentials.authenticated && !this.props.initialized) { From 8d40c0410774ce8e904dba2f1886b11464792458 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Fri, 19 Oct 2018 18:41:09 -0500 Subject: [PATCH 08/24] strip token from URL if auth fails --- embark-ui/src/containers/AppContainer.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/embark-ui/src/containers/AppContainer.js b/embark-ui/src/containers/AppContainer.js index cfb7793d7..531ef9a97 100644 --- a/embark-ui/src/containers/AppContainer.js +++ b/embark-ui/src/containers/AppContainer.js @@ -70,6 +70,12 @@ class AppContainer extends Component { this.props.authenticate(this.props.credentials.host, this.props.credentials.token); } + if (this.getQueryToken() && + !this.props.credentials.authenticated && + !this.props.credentials.authenticating) { + this.props.history.replace(this.stripQueryToken(this.props.location)); + } + if (this.getQueryToken() && this.props.credentials.authenticated) { this.props.history.replace(this.stripQueryToken(this.props.location)); } From 0ce26e44796808a6e5002b030325cdcaf99e1551 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Fri, 19 Oct 2018 18:51:39 -0500 Subject: [PATCH 09/24] include default credentials state on auth failure --- embark-ui/src/reducers/index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/embark-ui/src/reducers/index.js b/embark-ui/src/reducers/index.js index b65fac1a4..4dcf75e9d 100644 --- a/embark-ui/src/reducers/index.js +++ b/embark-ui/src/reducers/index.js @@ -200,7 +200,12 @@ function compilingContract(state = false, action) { return state; } -const DEFAULT_CREDENTIALS_STATE = {host: DEFAULT_HOST, token: '', authenticated: false, authenticating: false}; +const DEFAULT_CREDENTIALS_STATE = { + host: process.env.NODE_ENV === 'development' ? DEFAULT_HOST : window.location.host, + token: '', + authenticated: false, + authenticating: false +}; function credentials(state = DEFAULT_CREDENTIALS_STATE, action) { if (action.type === LOGOUT[SUCCESS]) { @@ -208,7 +213,7 @@ function credentials(state = DEFAULT_CREDENTIALS_STATE, action) { } if (action.type === AUTHENTICATE[FAILURE]) { - return {error: action.error, authenticated: false, authenticating: false}; + return {error: action.error, ...DEFAULT_CREDENTIALS_STATE}; } if (action.type === AUTHENTICATE[SUCCESS]) { From 2088624d83dd7929dbee0d180b051da0d1b18293 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Fri, 19 Oct 2018 19:41:45 -0500 Subject: [PATCH 10/24] on autho failure trigger logout, which clears localStorage We don't presently have a way to cleanly distinguish between auth attempts with query string vs. credentials from localStorage, particularly with respect to one kind failing vs. the other. This can create confusing behavior when e.g. copy/pasting an old/wrong URL+token, but then it works when refreshing the window/tab with URL minus the token. So, this commit simplifies the situation somewhat by triggering a logout if there's an auth failure. That will affect all open tabs/windows of the same browser but not other browsers, e.g. if one has embark-ui open in Chrome and Firefox. --- embark-ui/src/sagas/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/embark-ui/src/sagas/index.js b/embark-ui/src/sagas/index.js index 26cb905b0..99b64238a 100644 --- a/embark-ui/src/sagas/index.js +++ b/embark-ui/src/sagas/index.js @@ -273,6 +273,10 @@ export function *watchAuthenticateSuccess() { yield takeEvery(actions.AUTHENTICATE[actions.SUCCESS], saveCredentials); } +export function *watchAuthenticateFailure() { + yield takeEvery(actions.AUTHENTICATE[actions.FAILURE], logout); +} + export function *watchFetchCredentials() { yield takeEvery(actions.FETCH_CREDENTIALS[actions.REQUEST], fetchCredentials); } @@ -518,6 +522,7 @@ export default function *root() { fork(watchToggleBreakpoint), fork(watchAuthenticate), fork(watchAuthenticateSuccess), + fork(watchAuthenticateFailure), fork(watchLogout), fork(watchExplorerSearch), fork(watchFetchTheme), From 8b23d012ebe992cc607e1055ed648f4702132c01 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Fri, 19 Oct 2018 20:05:40 -0500 Subject: [PATCH 11/24] don't return Layout while authenticating --- embark-ui/src/containers/AppContainer.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/embark-ui/src/containers/AppContainer.js b/embark-ui/src/containers/AppContainer.js index 531ef9a97..107821714 100644 --- a/embark-ui/src/containers/AppContainer.js +++ b/embark-ui/src/containers/AppContainer.js @@ -103,6 +103,8 @@ class AppContainer extends Component { renderBody() { if (this.shouldRenderLogin()) { return ; + } else if (this.props.credentials.authenticating) { + return
; } return ( Date: Fri, 19 Oct 2018 20:05:53 -0500 Subject: [PATCH 12/24] whitespace --- embark-ui/src/containers/AppContainer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/embark-ui/src/containers/AppContainer.js b/embark-ui/src/containers/AppContainer.js index 107821714..2c0614423 100644 --- a/embark-ui/src/containers/AppContainer.js +++ b/embark-ui/src/containers/AppContainer.js @@ -107,9 +107,9 @@ class AppContainer extends Component { return
; } return ( - this.toggleTheme()} + toggleTheme={() => this.toggleTheme()} currentTheme={this.props.theme}> {routes} From 8d684bf1ef52de26e28e0a4198ab9a480df52be3 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 24 Oct 2018 14:35:40 -0500 Subject: [PATCH 13/24] make requireAuthentication clearer if authenticating or authenticated, do not require authentication --- embark-ui/src/containers/AppContainer.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/embark-ui/src/containers/AppContainer.js b/embark-ui/src/containers/AppContainer.js index 2c0614423..7121818e3 100644 --- a/embark-ui/src/containers/AppContainer.js +++ b/embark-ui/src/containers/AppContainer.js @@ -59,8 +59,8 @@ class AppContainer extends Component { } requireAuthentication() { - return !this.props.credentials.authenticating && - !this.props.credentials.authenticated && + return !(this.props.credentials.authenticating || + this.props.credentials.authenticated) && this.props.credentials.token && this.props.credentials.host; } From 53d6b9d7042110c32a8dd135d9917204e15b0bdb Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 24 Oct 2018 14:42:35 -0500 Subject: [PATCH 14/24] reorg getQueryToken, stripQueryToken in utils/utils --- embark-ui/src/containers/AppContainer.js | 16 +--------------- embark-ui/src/utils/utils.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/embark-ui/src/containers/AppContainer.js b/embark-ui/src/containers/AppContainer.js index 7121818e3..e325cc2a1 100644 --- a/embark-ui/src/containers/AppContainer.js +++ b/embark-ui/src/containers/AppContainer.js @@ -6,6 +6,7 @@ import routes from '../routes'; import Login from '../components/Login'; import Layout from "../components/Layout"; import { DEFAULT_HOST } from '../constants'; +import {getQueryToken, stripQueryToken} from '../utils/utils'; import { authenticate, fetchCredentials, logout, @@ -20,22 +21,7 @@ import {LIGHT_THEME, DARK_THEME} from '../constants'; import { getCredentials, getAuthenticationError, getProcesses, getTheme } from '../reducers/selectors'; -const qs = require('qs'); - class AppContainer extends Component { - getQueryToken() { - return qs.parse(this.props.location.search, {ignoreQueryPrefix: true}).token; - } - - stripQueryToken(location) { - const _location = Object.assign({}, location); - _location.search = _location.search.replace( - /(\?|&?)(token=[\w-]*)(&?)/, - (_, p1, p2, p3) => (p2 ? (p3 === '&' ? p1 : '') : '') - ); - return _location; - } - queryStringAuthenticate() { if (this.props.credentials.authenticating) { return; diff --git a/embark-ui/src/utils/utils.js b/embark-ui/src/utils/utils.js index e70aeb567..243758c5f 100644 --- a/embark-ui/src/utils/utils.js +++ b/embark-ui/src/utils/utils.js @@ -1,4 +1,5 @@ const Convert = require('ansi-to-html'); +import qs from 'qs'; export function last(array) { return array && array.length ? array[array.length - 1] : undefined; @@ -18,4 +19,16 @@ export function hashCode(str) { export function ansiToHtml(text) { const convert = new Convert(); return convert.toHtml(text.replace(/\n/g,'
')) + +export function getQueryToken(location) { + return qs.parse(location.search, {ignoreQueryPrefix: true}).token; +} + +export function stripQueryToken(location) { + const _location = Object.assign({}, location); + _location.search = _location.search.replace( + /(\?|&?)(token=[\w-]*)(&?)/, + (_, p1, p2, p3) => (p2 ? (p3 === '&' ? p1 : '') : '') + ); + return _location; } From a594b14f27b541d82be2753824abdcf3e8d25a1d Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 24 Oct 2018 14:43:23 -0500 Subject: [PATCH 15/24] combine token stripping logic, use utils --- embark-ui/src/containers/AppContainer.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/embark-ui/src/containers/AppContainer.js b/embark-ui/src/containers/AppContainer.js index e325cc2a1..cdd01c6f2 100644 --- a/embark-ui/src/containers/AppContainer.js +++ b/embark-ui/src/containers/AppContainer.js @@ -27,7 +27,7 @@ class AppContainer extends Component { return; } - const token = this.getQueryToken(); + const token = getQueryToken(this.props.lcation); if (!token) { return; @@ -56,14 +56,10 @@ class AppContainer extends Component { this.props.authenticate(this.props.credentials.host, this.props.credentials.token); } - if (this.getQueryToken() && - !this.props.credentials.authenticated && - !this.props.credentials.authenticating) { - this.props.history.replace(this.stripQueryToken(this.props.location)); - } - - if (this.getQueryToken() && this.props.credentials.authenticated) { - this.props.history.replace(this.stripQueryToken(this.props.location)); + if (getQueryToken(this.props.location) && + (!this.props.credentials.authenticating || + this.props.credentials.authenticated)) { + this.props.history.replace(stripQueryToken(this.props.location)); } if (this.props.credentials.authenticated && !this.props.initialized) { From 754266da17fa04077001b038d3f4ab51c7cb20d7 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 24 Oct 2018 14:45:22 -0500 Subject: [PATCH 16/24] formatting --- embark-ui/src/containers/AppContainer.js | 2 +- embark-ui/src/utils/utils.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/embark-ui/src/containers/AppContainer.js b/embark-ui/src/containers/AppContainer.js index cdd01c6f2..1bf0defe4 100644 --- a/embark-ui/src/containers/AppContainer.js +++ b/embark-ui/src/containers/AppContainer.js @@ -5,7 +5,7 @@ import {withRouter} from "react-router-dom"; import routes from '../routes'; import Login from '../components/Login'; import Layout from "../components/Layout"; -import { DEFAULT_HOST } from '../constants'; +import {DEFAULT_HOST} from '../constants'; import {getQueryToken, stripQueryToken} from '../utils/utils'; import { diff --git a/embark-ui/src/utils/utils.js b/embark-ui/src/utils/utils.js index 243758c5f..ac8c5857c 100644 --- a/embark-ui/src/utils/utils.js +++ b/embark-ui/src/utils/utils.js @@ -18,7 +18,8 @@ export function hashCode(str) { export function ansiToHtml(text) { const convert = new Convert(); - return convert.toHtml(text.replace(/\n/g,'
')) + return convert.toHtml(text.replace(/\n/g,'
')); +} export function getQueryToken(location) { return qs.parse(location.search, {ignoreQueryPrefix: true}).token; From 9ce967ca03e10f85e0a9331d8da67c19a0e4b0d7 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 24 Oct 2018 14:45:46 -0500 Subject: [PATCH 17/24] prefer `import` to `require()` --- embark-ui/src/utils/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embark-ui/src/utils/utils.js b/embark-ui/src/utils/utils.js index ac8c5857c..978b1e2c8 100644 --- a/embark-ui/src/utils/utils.js +++ b/embark-ui/src/utils/utils.js @@ -1,4 +1,4 @@ -const Convert = require('ansi-to-html'); +import Convert from 'ansi-to-html'; import qs from 'qs'; export function last(array) { From d150deb572b3abcd08f95ea149cb606e1356ab06 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 24 Oct 2018 14:46:50 -0500 Subject: [PATCH 18/24] error is `null` in DEFAULT_CREDENTIALS_STATE --- embark-ui/src/reducers/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/embark-ui/src/reducers/index.js b/embark-ui/src/reducers/index.js index 4dcf75e9d..2936be61a 100644 --- a/embark-ui/src/reducers/index.js +++ b/embark-ui/src/reducers/index.js @@ -204,7 +204,8 @@ const DEFAULT_CREDENTIALS_STATE = { host: process.env.NODE_ENV === 'development' ? DEFAULT_HOST : window.location.host, token: '', authenticated: false, - authenticating: false + authenticating: false, + error: null }; function credentials(state = DEFAULT_CREDENTIALS_STATE, action) { From 56177346df86c1d1b188f7f062beb84ddb598540 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 24 Oct 2018 14:47:01 -0500 Subject: [PATCH 19/24] set error null for action.type AUTHENTICATE[REQUEST] --- embark-ui/src/reducers/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embark-ui/src/reducers/index.js b/embark-ui/src/reducers/index.js index 2936be61a..4009268e5 100644 --- a/embark-ui/src/reducers/index.js +++ b/embark-ui/src/reducers/index.js @@ -226,7 +226,7 @@ function credentials(state = DEFAULT_CREDENTIALS_STATE, action) { } if (action.type === AUTHENTICATE[REQUEST]) { - return {...state, ...{authenticating: true}}; + return {...state, ...{authenticating: true, error: null}}; } return state; From d861b0b1af64a565ff3c733d2bfcf597cd2cd3a2 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 24 Oct 2018 14:54:47 -0500 Subject: [PATCH 20/24] prefer an empty React Fragment to an empty div --- embark-ui/src/containers/AppContainer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embark-ui/src/containers/AppContainer.js b/embark-ui/src/containers/AppContainer.js index 1bf0defe4..2a4509c36 100644 --- a/embark-ui/src/containers/AppContainer.js +++ b/embark-ui/src/containers/AppContainer.js @@ -86,7 +86,7 @@ class AppContainer extends Component { if (this.shouldRenderLogin()) { return ; } else if (this.props.credentials.authenticating) { - return
; + return ; } return ( Date: Wed, 24 Oct 2018 15:07:52 -0500 Subject: [PATCH 21/24] formatting --- embark-ui/src/containers/AppContainer.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/embark-ui/src/containers/AppContainer.js b/embark-ui/src/containers/AppContainer.js index 2a4509c36..a321e4f77 100644 --- a/embark-ui/src/containers/AppContainer.js +++ b/embark-ui/src/containers/AppContainer.js @@ -19,7 +19,9 @@ import { import {LIGHT_THEME, DARK_THEME} from '../constants'; -import { getCredentials, getAuthenticationError, getProcesses, getTheme } from '../reducers/selectors'; +import { + getCredentials, getAuthenticationError, getProcesses, getTheme +} from '../reducers/selectors'; class AppContainer extends Component { queryStringAuthenticate() { @@ -84,7 +86,11 @@ class AppContainer extends Component { renderBody() { if (this.shouldRenderLogin()) { - return ; + return ( + + ); } else if (this.props.credentials.authenticating) { return ; } From 10fa3fec9fdabb95a00d380ad2f01ecb644ac235 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 24 Oct 2018 15:08:16 -0500 Subject: [PATCH 22/24] consolidate DEFAULT_HOST logic --- embark-ui/src/constants.js | 4 ++-- embark-ui/src/containers/AppContainer.js | 2 +- embark-ui/src/reducers/index.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/embark-ui/src/constants.js b/embark-ui/src/constants.js index b2e1799d4..432f55eba 100644 --- a/embark-ui/src/constants.js +++ b/embark-ui/src/constants.js @@ -5,5 +5,5 @@ export const LIGHT_THEME = 'light'; export const DEPLOYMENT_PIPELINES = { injectedWeb3: 'injectedWeb3', embark: 'embark' -} -export const DEFAULT_HOST = 'localhost:8000'; +}; +export const DEFAULT_HOST = process.env.NODE_ENV === 'development' ? 'localhost:8000' : window.location.host; diff --git a/embark-ui/src/containers/AppContainer.js b/embark-ui/src/containers/AppContainer.js index a321e4f77..e0eb0b4b6 100644 --- a/embark-ui/src/containers/AppContainer.js +++ b/embark-ui/src/containers/AppContainer.js @@ -34,7 +34,7 @@ class AppContainer extends Component { if (!token) { return; } - const host = process.env.NODE_ENV === 'development' ? DEFAULT_HOST : window.location.host; + const host = DEFAULT_HOST; if (token === this.props.credentials.token && this.props.credentials.host === host) { return; } diff --git a/embark-ui/src/reducers/index.js b/embark-ui/src/reducers/index.js index 4009268e5..9de87adb2 100644 --- a/embark-ui/src/reducers/index.js +++ b/embark-ui/src/reducers/index.js @@ -201,7 +201,7 @@ function compilingContract(state = false, action) { } const DEFAULT_CREDENTIALS_STATE = { - host: process.env.NODE_ENV === 'development' ? DEFAULT_HOST : window.location.host, + host: DEFAULT_HOST, token: '', authenticated: false, authenticating: false, From a5c972903bb848a01b1d97ebeeb70dc1eadd7c8d Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 24 Oct 2018 15:14:30 -0500 Subject: [PATCH 23/24] formatting --- embark-ui/src/containers/AppContainer.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/embark-ui/src/containers/AppContainer.js b/embark-ui/src/containers/AppContainer.js index e0eb0b4b6..520b4a917 100644 --- a/embark-ui/src/containers/AppContainer.js +++ b/embark-ui/src/containers/AppContainer.js @@ -105,7 +105,11 @@ class AppContainer extends Component { } render() { - return
{this.renderBody()}
; + return ( +
+ {this.renderBody()} +
+ ); } } From 8a9b8f25ab93c9daefe464d8f4415ab6f056d899 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Thu, 25 Oct 2018 05:48:39 -0500 Subject: [PATCH 24/24] separate "should authenticate" logic from "do authenticate" logic but don't maintain separate methods for query string vs. props --- embark-ui/src/containers/AppContainer.js | 54 ++++++++++++++---------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/embark-ui/src/containers/AppContainer.js b/embark-ui/src/containers/AppContainer.js index 520b4a917..563235171 100644 --- a/embark-ui/src/containers/AppContainer.js +++ b/embark-ui/src/containers/AppContainer.js @@ -24,38 +24,46 @@ import { } from '../reducers/selectors'; class AppContainer extends Component { - queryStringAuthenticate() { - if (this.props.credentials.authenticating) { - return; - } - - const token = getQueryToken(this.props.lcation); - - if (!token) { - return; - } - const host = DEFAULT_HOST; - if (token === this.props.credentials.token && this.props.credentials.host === host) { - return; - } - return this.props.authenticate(host, token); - } - componentDidMount() { this.props.fetchCredentials(); this.props.fetchTheme(); } + doAuthenticate() { + let {host, token} = this.props.credentials; + const queryToken = getQueryToken(this.props.location); + + if (queryToken) { + host = DEFAULT_HOST; + token = queryToken; + } + + this.props.authenticate(host, token); + } + requireAuthentication() { - return !(this.props.credentials.authenticating || - this.props.credentials.authenticated) && - this.props.credentials.token && - this.props.credentials.host; + if (this.props.credentials.authenticating) { + return false; + } + + const queryToken = getQueryToken(this.props.location); + if (queryToken && !(queryToken === this.props.credentials.token && + this.props.credentials.host === DEFAULT_HOST)) { + return true; + } + + if (!this.props.credentials.authenticated && + this.props.credentials.host && + this.props.credentials.token) { + return true; + } + + return false; } componentDidUpdate(){ - if (!this.queryStringAuthenticate() && this.requireAuthentication()) { - this.props.authenticate(this.props.credentials.host, this.props.credentials.token); + if (this.requireAuthentication()) { + this.doAuthenticate(); } if (getQueryToken(this.props.location) &&