Skip to content

Instantly share code, notes, and snippets.

@morloy
Last active June 4, 2018 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morloy/fdf358083863afcad842dab3b45b2fc0 to your computer and use it in GitHub Desktop.
Save morloy/fdf358083863afcad842dab3b45b2fc0 to your computer and use it in GitHub Desktop.
import { Accounts } from 'meteor/accounts-base';
class LoginForm extends React.Component {
state = {
email: '',
password: '',
token: '',
requiresTwoFactor: false,
loading: false,
};
onSubmit = () => {
this.setState({ loading: true });
const { email, password, token } = this.state;
Accounts.callLoginMethod({
methodArguments: [{
user: { email },
twoFactorPassword: Accounts._hashPassword(password),
twoFactorToken: token ? Number(token) : null,
}],
userCallback: e => e && (
e.error === 'two-factor-required' ?
this.setState({ requiresTwoFactor: true, loading: false }) :
throw e,
});
};
render = () => (…)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment