From faf09b7d39c92be613e0fed81b4492086930bbb7 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 6 Sep 2018 13:24:39 -0400 Subject: [PATCH] use local cache to store the token --- embark-ui/package.json | 1 + embark-ui/src/containers/AppContainer.js | 10 +++++++++- embark-ui/src/services/cache.js | 15 +++++++++++++++ lib/modules/authenticator/index.js | 4 ++-- 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 embark-ui/src/services/cache.js diff --git a/embark-ui/package.json b/embark-ui/package.json index 7ef7a9606..f145e7c64 100644 --- a/embark-ui/package.json +++ b/embark-ui/package.json @@ -11,6 +11,7 @@ "connected-react-router": "^4.3.0", "history": "^4.7.2", "prop-types": "^15.6.2", + "query-string": "^6.1.0", "react": "^16.4.2", "react-ace": "^6.1.4", "react-copy-to-clipboard": "^5.0.1", diff --git a/embark-ui/src/containers/AppContainer.js b/embark-ui/src/containers/AppContainer.js index ba69c5f7f..78ec7759d 100644 --- a/embark-ui/src/containers/AppContainer.js +++ b/embark-ui/src/containers/AppContainer.js @@ -5,6 +5,7 @@ import {withRouter} from "react-router-dom"; import routes from '../routes'; import queryString from 'query-string'; +import {put as cachePut, get as cacheGet} from '../services/cache'; import { initBlockHeader, @@ -16,7 +17,14 @@ import { class AppContainer extends Component { componentDidMount() { - this.props.authenticate(queryString.parse(this.props.location.search).token); + let token; + if (this.props.location.search) { + token = queryString.parse(this.props.location.search).token; + cachePut('token', token); + } else { + token = cacheGet('token'); + } + this.props.authenticate(token); this.props.initBlockHeader(); this.props.fetchProcesses(); this.props.fetchVersions(); diff --git a/embark-ui/src/services/cache.js b/embark-ui/src/services/cache.js new file mode 100644 index 000000000..cf659cfa7 --- /dev/null +++ b/embark-ui/src/services/cache.js @@ -0,0 +1,15 @@ +export function put(key, value) { + window.localStorage.setItem(key, value); +} + +export function get(key) { + return window.localStorage.getItem(key); +} + +export function remove(key) { + return window.localStorage.removeItem(key); +} + +export function clear() { + window.localStorage.clear(); +} diff --git a/lib/modules/authenticator/index.js b/lib/modules/authenticator/index.js index e46e10261..abf28a5f8 100644 --- a/lib/modules/authenticator/index.js +++ b/lib/modules/authenticator/index.js @@ -6,9 +6,9 @@ class Authenticator { this.authToken = uuid(); - embark.events.on('outputDone', () => { + embark.events.once('outputDone', () => { embark.logger.info(__('Access the web backend with the following url: %s', - ('http://localhost:8000/embark/' + this.authToken).underline)); + ('http://localhost:8000/embark?token=' + this.authToken).underline)); }); embark.registerAPICall(