Fix login flow (#140)
This commit is contained in:
parent
384667ece1
commit
189668105b
2 changed files with 25 additions and 3 deletions
|
|
@ -10,6 +10,7 @@ export default class Root extends React.Component {
|
|||
static propTypes = {
|
||||
credentials: React.PropTypes.object,
|
||||
logoutRequest: React.PropTypes.object,
|
||||
loginRequest: React.PropTypes.object,
|
||||
actions: React.PropTypes.shape({
|
||||
goToSelectServer: React.PropTypes.func,
|
||||
goToSelectTeam: React.PropTypes.func,
|
||||
|
|
@ -23,6 +24,20 @@ export default class Root extends React.Component {
|
|||
componentDidMount() {
|
||||
// Any initialization logic for navigation, setting up the client, etc should go here
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (this.props.logoutRequest.status === RequestStatus.STARTED &&
|
||||
nextProps.logoutRequest.status === RequestStatus.SUCCESS) {
|
||||
this.props.actions.removeStorage();
|
||||
} else if (this.props.logoutRequest.status === RequestStatus.SUCCESS &&
|
||||
nextProps.logoutRequest.status === RequestStatus.NOT_STARTED) {
|
||||
this.init();
|
||||
}
|
||||
}
|
||||
|
||||
init = () => {
|
||||
if (this.props.logoutRequest.status === RequestStatus.SUCCESS) {
|
||||
this.props.actions.removeStorage().then(() => {
|
||||
setTimeout(this.loadStoreAndScene, 1000);
|
||||
|
|
@ -30,12 +45,18 @@ export default class Root extends React.Component {
|
|||
} else {
|
||||
this.loadStoreAndScene();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
loadStoreAndScene = () => {
|
||||
this.props.actions.loadStorage().then(() => {
|
||||
if (this.props.credentials.token && this.props.credentials.url) {
|
||||
this.props.actions.setStoreFromLocalData(this.props.credentials).then(this.props.actions.goToSelectTeam);
|
||||
this.props.actions.setStoreFromLocalData(this.props.credentials).then(() => {
|
||||
if (this.props.loginRequest.status === RequestStatus.SUCCESS) {
|
||||
this.props.actions.goToSelectTeam();
|
||||
} else {
|
||||
this.props.actions.goToSelectServer();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.props.actions.goToSelectServer();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ function mapStateToProps(state, ownProps) {
|
|||
return {
|
||||
...ownProps,
|
||||
credentials: state.entities.general.credentials,
|
||||
logoutRequest: state.requests.users.logout
|
||||
logoutRequest: state.requests.users.logout,
|
||||
loginRequest: state.requests.users.login
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue