Closed ninjagrizzly closed 8 years ago
This experience really helped me.. and.. How about if we do it this way ...
const RNApp = (props) => {
const { status, user, loggingIn } = props;
console.log('props', props);
if (status.connected === false){
return <Loading />;
} else if(user !== null){
return <LoggedIn />;
} else {
return <LoggedOut />;
}
};
handleSignIn() {
const { username, email, password, confirmPasswordInputVisible } = this.state;
if (!confirmPasswordInputVisible && this.validInput(true)) {
//NOTE because react-native-meteor doesn't login right away after sign in
//Meteor.loginWithPassword(email, password, (err) => {
Meteor.loginWithPassword(username, password, (err) => {
if (err) {
console.log(err.reason);
this.setState({ confirmPasswordInputVisible: true });
} else {
console.log('login success!');
this.setState({ error: 'no error'});
}
});
} else {
if(confirmPasswordInputVisible !== false) {
LayoutAnimation.configureNext(LayoutAnimation.Presets.spring);
this.setState({ confirmPasswordInputVisible: false });
this.setState({ error: null });
}
}
}
handleCreateAccount() {
const { username, email, password, confirmPasswordInputVisible } = this.state;
if(confirmPasswordInputVisible && this.validInput()) {
//Account.createUser({ email, password }, (err) => {
Accounts.createUser({ username: username, password: password }, (err) => {
if(err) {
this.setState({ error: err.reason });
} else {
//NOTE because react-native-meteor doesn't login right away after sign in
this.setState({ confirmPasswordInputVisible: false });
Meteor.loginWithPassword(username, password, (err) => {
if (err) {
this.setState({
error: err.reason,
confirmPasswordInputVisible: true
});
} else {
console.log('login success!');
}
});
}
});
} else {
if(confirmPasswordInputVisible !== true) {
LayoutAnimation.configureNext(LayoutAnimation.Presets.spring);
this.setState({ confirmPasswordInputVisible: true });
this.setState({ error: null });
}
}
}
This is very similar to #21 so I'm going to close this in favor of consolidating issues. I haven't thought through the issue yet but it's on my radar!
If i am trying to sign in with wrong login and password, Meteor send error, this is the handler
This code trying to this.setState, but after
loginWithPassword
the loggingIn status was changed, new<LoggedOut />
component was created, so this context specifies to old component andthis.setState
as a result working with unmounted component. Can you advice some elegant method to avoid it, please?)