Redirect to the correct url after login
This commit is contained in:
@ -28,6 +28,7 @@ class Layout extends React.Component {
|
||||
user: React.PropTypes.object.isRequired,
|
||||
search: React.PropTypes.bool,
|
||||
offline: React.PropTypes.bool,
|
||||
notifications: React.PropTypes.node,
|
||||
}
|
||||
|
||||
static defaultProps = {
|
||||
@ -67,6 +68,8 @@ class Layout extends React.Component {
|
||||
</Alert>
|
||||
) }
|
||||
|
||||
{ this.props.notifications }
|
||||
|
||||
<div className={ cx(styles.header) }>
|
||||
<div className={ styles.headerLeft }>
|
||||
<Link to="/" className={ styles.team }>Atlas</Link>
|
||||
|
@ -1,11 +1,12 @@
|
||||
import React from 'react';
|
||||
import { observer } from 'mobx-react';
|
||||
import { browserHistory } from 'react-router'
|
||||
import { browserHistory } from 'react-router';
|
||||
|
||||
import { Flex } from 'reflexbox';
|
||||
import Layout from 'components/Layout';
|
||||
import CenteredContent from 'components/CenteredContent';
|
||||
import SlackAuthLink from 'components/SlackAuthLink';
|
||||
import Alert from 'components/Alert';
|
||||
|
||||
import styles from './Home.scss';
|
||||
|
||||
@ -13,6 +14,7 @@ import styles from './Home.scss';
|
||||
export default class Home extends React.Component {
|
||||
static propTypes = {
|
||||
user: React.PropTypes.object.isRequired,
|
||||
location: React.PropTypes.object.isRequired,
|
||||
}
|
||||
|
||||
componentDidMount = () => {
|
||||
@ -21,12 +23,27 @@ export default class Home extends React.Component {
|
||||
}
|
||||
}
|
||||
|
||||
get notifications() {
|
||||
const notifications = [];
|
||||
const { state } = this.props.location;
|
||||
|
||||
if (state && state.nextPathname) {
|
||||
sessionStorage.removeItem('redirectTo');
|
||||
sessionStorage.setItem('redirectTo', state.nextPathname);
|
||||
notifications.push(<Alert key="login" info>Please login to continue</Alert>);
|
||||
}
|
||||
|
||||
return notifications;
|
||||
}
|
||||
|
||||
render() {
|
||||
const showLandingPageCopy = DEPLOYMENT === 'hosted';
|
||||
|
||||
return (
|
||||
<Flex auto>
|
||||
<Layout>
|
||||
<Layout
|
||||
notifications={ this.notifications }
|
||||
>
|
||||
<CenteredContent>
|
||||
{ showLandingPageCopy && (
|
||||
<div className={ styles.intro }>
|
||||
|
@ -12,7 +12,11 @@ class SlackAuth extends React.Component {
|
||||
}
|
||||
|
||||
componentDidMount = async () => {
|
||||
const { error, code, state } = this.props.location.query;
|
||||
const {
|
||||
error,
|
||||
code,
|
||||
state,
|
||||
} = this.props.location.query;
|
||||
|
||||
if (error) {
|
||||
if (error === 'access_denied') {
|
||||
@ -34,7 +38,10 @@ class SlackAuth extends React.Component {
|
||||
}
|
||||
} else {
|
||||
// Regular Slack authentication
|
||||
this.props.user.authWithSlack(code, state);
|
||||
const redirectTo = sessionStorage.getItem('redirectTo');
|
||||
sessionStorage.removeItem('redirectTo');
|
||||
|
||||
this.props.user.authWithSlack(code, state, redirectTo);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ class UserStore {
|
||||
return this.oauthState;
|
||||
}
|
||||
|
||||
@action authWithSlack = async (code, state) => {
|
||||
@action authWithSlack = async (code, state, redirectTo) => {
|
||||
if (state !== this.oauthState) {
|
||||
browserHistory.push('/auth-error');
|
||||
return;
|
||||
@ -50,7 +50,7 @@ class UserStore {
|
||||
|
||||
let res;
|
||||
try {
|
||||
res = await client.post('/auth.slack', { code: code });
|
||||
res = await client.post('/auth.slack', { code });
|
||||
} catch (e) {
|
||||
browserHistory.push('/auth-error');
|
||||
return;
|
||||
@ -59,7 +59,7 @@ class UserStore {
|
||||
this.user = res.data.user;
|
||||
this.team = res.data.team;
|
||||
this.token = res.data.accessToken;
|
||||
browserHistory.replace('/dashboard');
|
||||
browserHistory.replace(redirectTo || '/');
|
||||
}
|
||||
|
||||
constructor() {
|
||||
@ -70,7 +70,7 @@ class UserStore {
|
||||
this.token = data.token;
|
||||
this.oauthState = data.oauthState;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default UserStore;
|
||||
export {
|
||||
|
Reference in New Issue
Block a user