cabana: github sign out button; remove gh_access_token from URL immediately after persisting

main
Andy Haden 2017-08-09 13:03:20 -07:00
parent c7db2c9734
commit 28a8a5513e
4 changed files with 33 additions and 4 deletions

View File

@ -20,7 +20,9 @@ const CanStreamerWorker = require('./workers/CanStreamerWorker.worker.js');
import debounce from './utils/debounce';
import EditMessageModal from './components/EditMessageModal';
import LoadingBar from './components/LoadingBar';
import {persistDbc, fetchPersistedDbc} from './api/localstorage';
import {persistDbc,
fetchPersistedDbc,
unpersistGithubAuthToken} from './api/localstorage';
import OpenDbc from './api/OpenDbc';
import UnloggerClient from './api/unlogger';
import PandaReader from './api/panda-reader';
@ -68,7 +70,9 @@ export default class CanExplorer extends Component {
attemptingPandaConnection: false,
pandaNoDeviceSelected: false,
live: false,
isGithubAuthenticated: props.githubAuthToken !== null && props.githubAuthToken !== undefined,
};
this.openDbcClient = new OpenDbc(props.githubAuthToken);
if(USE_UNLOGGER) {
this.unloggerClient = new UnloggerClient();
@ -100,6 +104,7 @@ export default class CanExplorer extends Component {
this.onStreamedCanMessagesProcessed = this.onStreamedCanMessagesProcessed.bind(this);
this.showingModal = this.showingModal.bind(this);
this.lastMessageEntriesById = this.lastMessageEntriesById.bind(this);
this.githubSignOut = this.githubSignOut.bind(this);
}
componentWillMount() {
@ -576,6 +581,12 @@ export default class CanExplorer extends Component {
});
}
githubSignOut(e) {
unpersistGithubAuthToken();
this.setState({isGithubAuthenticated: false});
e.preventDefault();
}
render() {
return (
@ -587,8 +598,12 @@ export default class CanExplorer extends Component {
<div className='cabana-header'>
<a className='cabana-header-logo' href=''>Comma Cabana</a>
<div className='cabana-header-account'>
{this.props.githubAuthToken ?
<p>GitHub Authenticated</p>
{this.state.isGithubAuthenticated ?
<div>
<p>GitHub Authenticated</p>
<p className='cabana-header-account-signout'
onClick={this.githubSignOut}>Sign out</p>
</div>
: this.loginWithGithub()
}
</div>

View File

@ -21,6 +21,10 @@ export function fetchPersistedGithubAuthToken() {
return window.localStorage.getItem(GITHUB_AUTH_TOKEN_LOCALSTORAGE_KEY);
}
export function unpersistGithubAuthToken() {
window.localStorage.removeItem(GITHUB_AUTH_TOKEN_LOCALSTORAGE_KEY);
}
export function persistGithubAuthToken(token) {
return window.localStorage.setItem(GITHUB_AUTH_TOKEN_LOCALSTORAGE_KEY, token);
}

View File

@ -50,6 +50,14 @@
&-account {
float: right;
width: 177px;
&-signout {
cursor: pointer;
font-size: 12px;
color: rgba(255,255,255,0.9);
&:hover {
text-decoration: underline;
}
}
a {
color: #fff;
font-size: 14px;

View File

@ -5,7 +5,7 @@ import React from 'react';
import ReactDOM from 'react-dom';
import CanExplorer from './CanExplorer';
import AcuraDbc from './acura-dbc';
import {getUrlParameter} from './utils/url';
import {getUrlParameter, modifyQueryParameters} from './utils/url';
import {GITHUB_AUTH_TOKEN_KEY} from './config';
import {fetchPersistedDbc,
fetchPersistedGithubAuthToken,
@ -48,6 +48,8 @@ const authTokenQueryParam = getUrlParameter(GITHUB_AUTH_TOKEN_KEY);
if(authTokenQueryParam !== null) {
props.githubAuthToken = authTokenQueryParam;
persistGithubAuthToken(authTokenQueryParam);
const urlNoAuthToken = modifyQueryParameters({remove: [GITHUB_AUTH_TOKEN_KEY]});
window.location.href = urlNoAuthToken;
} else {
props.githubAuthToken = fetchPersistedGithubAuthToken();
}