Skip to content

Commit 24e832e

Browse files
committed
feat(User): .loginWithEmail
1 parent 0bc00c8 commit 24e832e

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/user.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,24 @@ module.exports = function(AV) {
10101010
return user.logIn();
10111011
},
10121012

1013+
/**
1014+
* Logs in a user with email and password.
1015+
*
1016+
* @since 3.13.0
1017+
* @param {String} email The user's email.
1018+
* @param {String} password The password to log in with.
1019+
* @return {Promise} A promise that is fulfilled with the user when
1020+
* the login completes.
1021+
*/
1022+
loginWithEmail(email, password) {
1023+
const user = AV.Object._create('_User');
1024+
user._finishFetch({
1025+
email,
1026+
password,
1027+
});
1028+
return user.logIn();
1029+
},
1030+
10131031
/**
10141032
* Sign up or logs in a user with a third party auth data(AccessToken).
10151033
* On success, this saves the session to disk, so you can retrieve the currently

storage.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ export class User extends Object {
661661
mobilePhone: string,
662662
smsCode: string
663663
): Promise<User>;
664+
static loginWithEmail(email: string, password: string): Promise<User>;
664665
static loginWithAuthData(
665666
authData: object,
666667
platform: string,

test/user.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ describe('User', function() {
5252
code: 210,
5353
});
5454
});
55+
56+
it('should loginWithEmail', () =>
57+
AV.User.loginWithEmail(email, password).then(function(user) {
58+
expect(user.get('username')).to.be(username);
59+
}));
5560
});
5661

5762
describe('Current User', function() {

0 commit comments

Comments
 (0)