Skip to content

Commit

Permalink
Fix redirect after auth (#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
isaldin authored and levenecav committed Aug 31, 2018
1 parent 740dede commit 8c3ad02
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
22 changes: 5 additions & 17 deletions src/components/Authorization/Authorization.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ type PropsType = {
environment: Environment,
handleLogin: () => void,
isSignUp: ?boolean,
alone: ?boolean,
match: matchShape,
showAlert: (input: AddAlertInputType) => void,
onCloseModal?: () => void,
Expand Down Expand Up @@ -139,9 +138,7 @@ class Authorization extends Component<PropsType, StateType> {
};

handleAlertOnClick = (): void => {
if (this.props.alone) {
window.location = '/';
}
window.location = '/';
};

handleRegistrationClick = () => {
Expand Down Expand Up @@ -208,10 +205,8 @@ class Authorization extends Component<PropsType, StateType> {
handleLoginClick = () => {
this.setState({ isLoading: true, errors: null });
const {
alone,
match: {
location: {
pathname,
query: { from },
},
},
Expand All @@ -232,16 +227,10 @@ class Authorization extends Component<PropsType, StateType> {
setCookie('__jwt', { value: jwt }, expirationDate);
if (this.props.handleLogin) {
this.props.handleLogin();
if (alone) {
if (from && from !== '') {
window.location.replace(from);
} else {
window.location = '/';
}
} else if (pathname === '/login') {
window.location = '/';
if (from && from !== '') {
window.location.replace(from);
} else {
window.location.reload();
window.location = '/';
}
}
return;
Expand Down Expand Up @@ -577,7 +566,7 @@ class Authorization extends Component<PropsType, StateType> {
};

render() {
const { alone, onCloseModal, isResetPassword, isLogin } = this.props;
const { onCloseModal, isResetPassword, isLogin } = this.props;
const text = 'Please Type new password';
const description = isResetPassword ? text : '';
const {
Expand All @@ -604,7 +593,6 @@ class Authorization extends Component<PropsType, StateType> {
{isRecoverPassword || isResetPassword ? null : (
<AuthorizationHeader
fullWidth={isLogin}
alone={alone}
isSignUp={isSignUp}
onClick={this.handleClick}
selected={selected}
Expand Down
4 changes: 2 additions & 2 deletions src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,14 +492,14 @@ const routes = (
return <Component isSignUp {...props} />;
}
}
return <Component isSignUp alone {...props} />;
return <Component isSignUp {...props} />;
}}
/>

<Route
path="/login"
Component={Login}
render={({ Component, props }) => <Component alone {...props} />}
render={({ Component, props }) => <Component {...props} />}
/>

<Route path="/logout" Component={Logout} />
Expand Down

0 comments on commit 8c3ad02

Please sign in to comment.