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