Skip to content

Commit 4b76552

Browse files
authored
Merge pull request #136 from bratelefant/pr-set-subs-unready-on-disc
add 2fa login
2 parents c3cee6e + cc36a64 commit 4b76552

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

docs/api.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,16 @@ Returns true if attempting to login
6565

6666
Returns true if attempting to logout
6767

68-
### `Meteor.loginWithPassword`
68+
### `Meteor.loginWithPassword(selector, password, callback)`
69+
70+
Logs a user in. If selector is a string containing `@`, then this will be interpreted as an email, other strings as a username. The selector can also be an object with a single key `email`, `id` or `username`.
71+
The optional Callback is called with a single `Error` argument on failure.
72+
73+
If 2fa is enabled, the `error` property of the argument may be `no-2fa-code`. Read more in [the Meteor docs](https://docs.meteor.com/api/accounts#Meteor-loginWithPassword)
74+
75+
### `Meteor.loginWithPasswordAnd2faCode(selector, password, code, callback)`
76+
77+
Logs a user in, same as `loginWithPassword`, but providing a 2fa token via the argument `code`. Read more on this [in the Meteor docs](https://docs.meteor.com/packages/accounts-2fa.html).
6978

7079
### `Meteor.logout`
7180

src/user/User.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,28 @@ const User = {
7373
}
7474
);
7575
},
76+
loginWithPasswordAnd2faCode(selector, password, code, callback) {
77+
this._isTokenLogin = false;
78+
if (typeof selector === 'string') {
79+
if (selector.indexOf('@') === -1) selector = { username: selector };
80+
else selector = { email: selector };
81+
}
82+
83+
User._startLoggingIn();
84+
Meteor.call(
85+
'login',
86+
{
87+
user: selector,
88+
password: hashPassword(password),
89+
code,
90+
},
91+
(err, result) => {
92+
User._handleLoginCallback(err, result);
93+
94+
typeof callback == 'function' && callback(err);
95+
}
96+
);
97+
},
7698
logoutOtherClients(callback = () => {}) {
7799
Meteor.call('getNewToken', (err, res) => {
78100
if (err) return callback(err);

0 commit comments

Comments
 (0)