remove token from URL and replace location in history if auth'd

This commit is contained in:
Michael Bradley, Jr 2018-10-19 14:35:33 -05:00
parent 1b20bbbeb8
commit 2abcfe5de0
1 changed files with 14 additions and 1 deletions

View File

@ -23,8 +23,12 @@ import { getCredentials, getAuthenticationError, getProcesses, getTheme } from '
const qs = require('qs'); const qs = require('qs');
class AppContainer extends Component { class AppContainer extends Component {
getToken() {
return qs.parse(this.props.location.search, {ignoreQueryPrefix: true}).token;
}
queryStringAuthenticate() { queryStringAuthenticate() {
const token = qs.parse(this.props.location.search, {ignoreQueryPrefix: true}).token; const token = this.getToken();
if (!token) { if (!token) {
return; return;
@ -50,6 +54,15 @@ class AppContainer extends Component {
this.props.authenticate(this.props.credentials.host, this.props.credentials.token); 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) { if (this.props.credentials.authenticated && !this.props.initialized) {
this.props.fetchProcesses(); this.props.fetchProcesses();
this.props.fetchServices(); this.props.fetchServices();