Skip to content

Commit

Permalink
Merge 6e9c2c7 into ff82784
Browse files Browse the repository at this point in the history
  • Loading branch information
osteele committed May 16, 2018
2 parents ff82784 + 6e9c2c7 commit 068f61d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
16 changes: 6 additions & 10 deletions src/data/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@ import axios from 'axios';

const ACCESS_TOKEN_KEY = 'abeAccessToken';

// axios.interceptors.request.use((config) => {
// if (accessToken) {
// // eslint-disable-next-line no-param-reassign
// config.headers.common.Authorization = `Bearer ${accessToken}`;
// }
// return config;
// }, Promise.reject);
export function clearAccessToken() {
localStorage.removeItem(ACCESS_TOKEN_KEY);
axios.defaults.headers.common.Authorization = null;
}

export function setAccessToken(accessToken) {
localStorage[ACCESS_TOKEN_KEY] = accessToken;
axios.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
}

export function clearAccessToken() {
localStorage.removeItem(ACCESS_TOKEN_KEY);
axios.defaults.headers.common.Authorization = null;
export function canSignOut() {
return Boolean(localStorage[ACCESS_TOKEN_KEY]);
}

export function removeOauthParams(url) {
Expand Down
8 changes: 7 additions & 1 deletion src/sidebar/footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import * as React from 'react';

const Footer = _props => (
const Footer = props => (
<footer>
<div className="footer-message">
<p>
Expand All @@ -20,6 +20,12 @@ const Footer = _props => (
View on GitHub
</a>
</p>
{props.onSignOut && (
<span>
&nbsp;|&nbsp;
<a onClick={props.onSignOut}>Sign Out</a>
</span>
)}
</div>
</footer>
);
Expand Down
7 changes: 6 additions & 1 deletion src/sidebar/sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import GenerateICSPane from './generate-ics-pane';
import LinkPane from './link-pane';
import MarkdownGuide from './markdown-guide';
import SidebarItemContainer from './sidebar-item-wrapper';
import { canSignOut, clearAccessToken } from '../data/auth';

const Sidebar = (props) => {
const {
Expand Down Expand Up @@ -81,6 +82,10 @@ const Sidebar = (props) => {
</div>
);

const onSignOut = () => {
clearAccessToken();
window.location.reload();
};
const sidebarClasses = `app-sidebar${props.isCollapsed ? ' collapsed' : ' expanded'}`;
return (
<div className={sidebarClasses}>
Expand All @@ -90,7 +95,7 @@ const Sidebar = (props) => {
toggleSidebarCollapsed={props.toggleSidebarCollapsed}
/>
<div className="sidebar-content">{content}</div>
<Footer class="sidebar-footer" />
<Footer class="sidebar-footer" onSignOut={canSignOut() && onSignOut} />
</div>
</div>
);
Expand Down

0 comments on commit 068f61d

Please sign in to comment.