Auto log user after register
This commit is contained in:
parent
3f2fd35195
commit
ebaf17e6e4
@ -34,7 +34,9 @@ export function updateUser(config) {
|
||||
export function userSignUp(config) {
|
||||
return request(
|
||||
"USER_SIGNUP",
|
||||
configureAxios().post("/users/signup", config)
|
||||
configureAxios().post("/users/signup", config), [
|
||||
() => loginUser(config.username, config.password),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,12 @@ import { bindActionCreators } from "redux"
|
||||
|
||||
import { userSignUp } from "../../actions/users"
|
||||
|
||||
function mapStateToProps(state) {
|
||||
return {
|
||||
isLogged: state.userStore.get("isLogged"),
|
||||
};
|
||||
}
|
||||
|
||||
const mapDispatchToProps = (dispatch) =>
|
||||
bindActionCreators({ userSignUp }, dispatch)
|
||||
|
||||
@ -20,6 +26,13 @@ class UserSignUp extends React.PureComponent {
|
||||
"password_confirm": this.refs.passwordConfirm.value,
|
||||
});
|
||||
}
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (!nextProps.isLogged) {
|
||||
return
|
||||
}
|
||||
// Redirect home
|
||||
nextProps.router.push("/");
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
<div className="container">
|
||||
@ -53,4 +66,4 @@ class UserSignUp extends React.PureComponent {
|
||||
);
|
||||
}
|
||||
}
|
||||
export default connect(null, mapDispatchToProps)(UserSignUp);
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(UserSignUp);
|
||||
|
@ -50,6 +50,9 @@ export function request(eventPrefix, promise, callbackEvents = null, mainPayload
|
||||
})
|
||||
if (callbackEvents) {
|
||||
for (let event of callbackEvents) {
|
||||
if (typeof event === 'function') {
|
||||
event = event();
|
||||
}
|
||||
dispatch(event);
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +88,14 @@ export default function getRoutes(App) {
|
||||
childRoutes: [
|
||||
{
|
||||
path: "/users/signup",
|
||||
component: UserSignUp
|
||||
component: UserSignUp,
|
||||
onEnter: function(nextState, replace, next) {
|
||||
if (isLoggedIn()) {
|
||||
// User is already logged in, redirect him to the default route
|
||||
replace(defaultRoute);
|
||||
}
|
||||
next();
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "/users/login",
|
||||
|
Loading…
x
Reference in New Issue
Block a user