Skip to content

Commit 34c7176

Browse files
author
David Silva
committed
In signup page, if the user is authenticated, redirect to /profile
1 parent fda21a4 commit 34c7176

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/containers/signup/index.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,25 @@ import femaleOctocat from '../../assets/images/femalecodertocat.png';
44
import { Link } from 'react-router-dom';
55
import { BACKEND_URL, PROD_URL } from '../../constants';
66
import { Helmet } from 'react-helmet';
7+
import { readEndpoint } from 'redux-json-api';
8+
import PropTypes from 'prop-types';
9+
import { bindActionCreators } from 'redux';
10+
import { connect } from 'react-redux';
11+
import ReactRouterPropTypes from 'react-router-prop-types';
712

813
class Signup extends React.Component {
14+
static propTypes = {
15+
readEndpoint: PropTypes.func.isRequired,
16+
authenticated: PropTypes.bool.isRequired,
17+
history: ReactRouterPropTypes.history.isRequired,
18+
}
19+
20+
componentWillReceiveProps() {
21+
if (this.props.authenticated) {
22+
this.props.history.push('/profile');
23+
}
24+
}
25+
926
render() {
1027
return(
1128
<section id="hero" className="dark-bg img-bg img-bg-soft" style={{ backgroundImage: `url(${blueBg})` }}>
@@ -49,4 +66,15 @@ class Signup extends React.Component {
4966
}
5067
}
5168

52-
export default Signup;
69+
const mapStateToProps = (state) => {
70+
const { profile } = state;
71+
return {
72+
authenticated: profile.authenticated || false,
73+
};
74+
};
75+
76+
const mapDispatchToProps = (dispatch) => bindActionCreators({
77+
readEndpoint,
78+
}, dispatch);
79+
80+
export default connect(mapStateToProps, mapDispatchToProps)(Signup);

0 commit comments

Comments
 (0)