Skip to content

Commit d237eb9

Browse files
committed
added missing reauthenticate method for currentUser and renamed sendPasswordResetWithEmail to sendPasswordResetEmail
1 parent dd6ce1d commit d237eb9

File tree

2 files changed

+30
-32
lines changed

2 files changed

+30
-32
lines changed

lib/modules/auth.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export default class Auth extends Base {
9595
return promisify('signInWithEmail', FirestackAuth)(email, password);
9696
}
9797

98+
// TODO move user methods to User class
9899

99100
/**
100101
* Update the current user's email
@@ -139,30 +140,23 @@ export default class Auth extends Base {
139140
return promisify('signInWithCustomToken', FirestackAuth)(customToken);
140141
}
141142

142-
// TODO - below methods are not in web api / i think the're signInWithCredential
143+
// TODO credential type definition
143144
/**
144145
* Sign the user in with a third-party authentication provider
145-
* @param {string} provider The name of the provider to use for login
146-
* @param {string} authToken The authToken granted by the provider
147-
* @param {string} authSecret The authToken secret granted by the provider
148146
* @return {Promise} A promise resolved upon completion
149147
*/
150-
signInWithProvider(provider: string, authToken: string, authSecret: string): Promise<Object> {
151-
return promisify('signInWithProvider', FirestackAuth)(provider, authToken, authSecret);
148+
signInWithCredential(credential): Promise<Object> {
149+
return promisify('signInWithProvider', FirestackAuth)(credential.provider, credential.token, credential.secret);
152150
}
153151

154152
/**
155153
* Re-authenticate a user with a third-party authentication provider
156-
* @param {string} provider The provider name
157-
* @param {string} token The authToken granted by the provider
158-
* @param {string} secret The authTokenSecret granted by the provider
159154
* @return {Promise} A promise resolved upon completion
160155
*/
161-
reauthenticateWithCredentialForProvider(provider: string, token: string, secret: string): Promise<Object> {
162-
return promisify('reauthenticateWithCredentialForProvider', FirestackAuth)(provider, token, secret);
156+
reauthenticateUser(credential): Promise<Object> {
157+
return promisify('reauthenticateWithCredentialForProvider', FirestackAuth)(credential.provider, credential.token, credential.secret);
163158
}
164159

165-
166160
/**
167161
* Sign a user in anonymously
168162
* @return {Promise} A promise resolved upon completion
@@ -175,7 +169,7 @@ export default class Auth extends Base {
175169
* Send reset password instructions via email
176170
* @param {string} email The email to send password reset instructions
177171
*/
178-
sendPasswordResetWithEmail(email: string): Promise<Object> {
172+
sendPasswordResetEmail(email: string): Promise<Object> {
179173
return promisify('sendPasswordResetWithEmail', FirestackAuth)(email);
180174
}
181175

lib/modules/user.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import promisify from '../utils/promisify';
2-
import { Base } from './base';
3-
4-
1+
// TODO refreshToken property
2+
// TODO reload() method
53
export default class User {
64
constructor(authClass, authObj) {
75
this._auth = authClass;
@@ -33,7 +31,7 @@ export default class User {
3331
* @returns {*}
3432
* @private
3533
*/
36-
_getOrNull(prop) {
34+
_valueOrNull(prop) {
3735
if (!this._user) return null;
3836
if (!Object.hasOwnProperty.call(this._user, prop)) return null;
3937
return this._user[prop];
@@ -44,47 +42,48 @@ export default class User {
4442
*/
4543

4644
get displayName() {
47-
return this._getOrNull('displayName');
45+
return this._valueOrNull('displayName');
4846
}
4947

5048
get email() {
51-
return this._getOrNull('email');
49+
return this._valueOrNull('email');
5250
}
5351

5452
get emailVerified() {
55-
return this._getOrNull('emailVerified');
53+
return this._valueOrNull('emailVerified');
5654
}
5755

5856
get isAnonymous() {
59-
return !this._getOrNull('email') && this._getOrNull('providerId') === 'firebase';
57+
return !this._valueOrNull('email') && this._valueOrNull('providerId') === 'firebase';
6058
}
6159

6260
get photoURL() {
63-
return this._getOrNull('photoURL');
61+
return this._valueOrNull('photoURL');
6462
}
6563

6664
get photoUrl() {
67-
return this._getOrNull('photoURL');
65+
return this._valueOrNull('photoURL');
6866
}
6967

7068
// TODO no android method yet, the SDK does have .getProviderData but returns as a List.
7169
// get providerData() {
72-
// return this._getOrNull('providerData');
70+
// return this._valueOrNull('providerData');
7371
// }
7472

7573
get providerId() {
76-
return this._getOrNull('providerId');
74+
return this._valueOrNull('providerId');
7775
}
7876

79-
// TODO no
77+
// TODO no android method?
8078
// get refreshToken() {
81-
// return this._getOrNull('refreshToken');
79+
// return this._valueOrNull('refreshToken');
8280
// }
8381

8482
get uid() {
85-
return this._getOrNull('uid');
83+
return this._valueOrNull('uid');
8684
}
8785

86+
// noinspection ReservedWordAsName
8887
/**
8988
* METHODS
9089
*/
@@ -97,8 +96,13 @@ export default class User {
9796
return this._auth.getToken(...args);
9897
}
9998

99+
get reauthenticate() {
100+
return this._auth.reauthenticateUser;
101+
}
102+
103+
// TODO match errors to auth/something errors from firebase web api
100104
get updateEmail() {
101-
if (this.isAnonymous) return () => Promise.reject(new Error('Can not update email on an annonymous user.'));
105+
if (this.isAnonymous) return () => Promise.reject(new Error('Can not update email on an anonymous user.'));
102106
return this._auth.updateEmail;
103107
}
104108

@@ -107,12 +111,12 @@ export default class User {
107111
}
108112

109113
get updatePassword() {
110-
if (this.isAnonymous) return () => Promise.reject(new Error('Can not update password on an annonymous user.'));
114+
if (this.isAnonymous) return () => Promise.reject(new Error('Can not update password on an anonymous user.'));
111115
return this._auth.updatePassword;
112116
}
113117

114118
get sendEmailVerification() {
115-
if (this.isAnonymous) return () => Promise.reject(new Error('Can not verify email on an annonymous user.'));
119+
if (this.isAnonymous) return () => Promise.reject(new Error('Can not verify email on an anonymous user.'));
116120
return this._auth.sendEmailVerification;
117121
}
118122
}

0 commit comments

Comments
 (0)