- moved user methods out of auth class into user class
- lint/flow
This commit is contained in:
parent
7715b2c061
commit
efb07c47c7
|
@ -269,7 +269,7 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
|||
}
|
||||
|
||||
@ReactMethod
|
||||
public void reauthenticateWithCredentialForProvider(final String provider, final String authToken, final String authSecret, final Callback callback) {
|
||||
public void reauthenticate(final String provider, final String authToken, final String authSecret, final Callback callback) {
|
||||
// TODO:
|
||||
Utils.todoNote(TAG, "reauthenticateWithCredentialForProvider", callback);
|
||||
// AuthCredential credential;
|
||||
|
@ -351,7 +351,7 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
|||
}
|
||||
|
||||
@ReactMethod
|
||||
public void deleteUser(final Callback callback) {
|
||||
public void delete(final Callback callback) {
|
||||
FirebaseUser user = mAuth.getCurrentUser();
|
||||
if (user != null) {
|
||||
user.delete()
|
||||
|
@ -488,7 +488,7 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule {
|
|||
|
||||
|
||||
@ReactMethod
|
||||
public void reloadUser(final Callback callback) {
|
||||
public void reload(final Callback callback) {
|
||||
FirebaseUser user = mAuth.getCurrentUser();
|
||||
|
||||
if (user == null) {
|
||||
|
|
|
@ -125,50 +125,6 @@ export default class Auth extends Base {
|
|||
return promisify('signInWithEmail', FirebaseAuth, 'auth/')(email, password);
|
||||
}
|
||||
|
||||
// TODO move user methods to User class
|
||||
|
||||
/**
|
||||
* Update the current user's email
|
||||
* @param {string} email The user's _new_ email
|
||||
* @return {Promise} A promise resolved upon completion
|
||||
*/
|
||||
updateEmail(email: string): Promise<Object> {
|
||||
return promisify('updateUserEmail', FirebaseAuth, 'auth/')(email);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send verification email to current user.
|
||||
*/
|
||||
sendEmailVerification(): Promise<Object> {
|
||||
return promisify('sendEmailVerification', FirebaseAuth, 'auth/')();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the current user's password
|
||||
* @param {string} password the new password
|
||||
* @return {Promise}
|
||||
*/
|
||||
updatePassword(password: string): Promise<Object> {
|
||||
return promisify('updateUserPassword', FirebaseAuth, 'auth/')(password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the current user's profile
|
||||
* @param {Object} updates An object containing the keys listed [here](https://firebase.google.com/docs/auth/ios/manage-users#update_a_users_profile)
|
||||
* @return {Promise}
|
||||
*/
|
||||
updateProfile(updates: Object = {}): Promise<Object> {
|
||||
return promisify('updateUserProfile', FirebaseAuth, 'auth/')(updates);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param credential
|
||||
*/
|
||||
link(credential: CredentialType) {
|
||||
return promisify('link', FirebaseAuth, 'auth/')(credential.provider, credential.token, credential.secret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign the user in with a custom auth token
|
||||
* @param {string} customToken A self-signed custom auth token.
|
||||
|
@ -186,14 +142,6 @@ export default class Auth extends Base {
|
|||
return promisify('signInWithProvider', FirebaseAuth, 'auth/')(credential.provider, credential.token, credential.secret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-authenticate a user with a third-party authentication provider
|
||||
* @return {Promise} A promise resolved upon completion
|
||||
*/
|
||||
reauthenticateUser(credential: CredentialType): Promise<Object> {
|
||||
return promisify('reauthenticateWithCredentialForProvider', FirebaseAuth, 'auth/')(credential.provider, credential.token, credential.secret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send reset password instructions via email
|
||||
* @param {string} email The email to send password reset instructions
|
||||
|
@ -202,30 +150,6 @@ export default class Auth extends Base {
|
|||
return promisify('sendPasswordResetWithEmail', FirebaseAuth, 'auth/')(email);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the current user
|
||||
* @return {Promise}
|
||||
*/
|
||||
deleteUser(): Promise<Object> {
|
||||
return promisify('deleteUser', FirebaseAuth, 'auth/')();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the current user
|
||||
* @return {Promise}
|
||||
*/
|
||||
reloadUser(): Promise<Object> {
|
||||
return promisify('reloadUser', FirebaseAuth, 'auth/')();
|
||||
}
|
||||
|
||||
/**
|
||||
* get the token of current user
|
||||
* @return {Promise}
|
||||
*/
|
||||
getToken(): Promise<Object> {
|
||||
return promisify('getToken', FirebaseAuth, 'auth/')();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently signed in user
|
||||
* @return {Promise}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { NativeModules, NativeEventEmitter } from 'react-native';
|
||||
import { NativeModules } from 'react-native';
|
||||
import { promisify } from './../../utils';
|
||||
|
||||
const FirebaseAuth = NativeModules.RNFirebaseAuth;
|
||||
|
||||
|
@ -54,41 +55,31 @@ export default class User {
|
|||
* PROPERTIES
|
||||
*/
|
||||
|
||||
get displayName() {
|
||||
get displayName(): String|null {
|
||||
return this._valueOrNull('displayName');
|
||||
}
|
||||
|
||||
get email() {
|
||||
get email(): String|null {
|
||||
return this._valueOrNull('email');
|
||||
}
|
||||
|
||||
get emailVerified() {
|
||||
get emailVerified(): Boolean {
|
||||
return this._valueOrNull('emailVerified');
|
||||
}
|
||||
|
||||
get isAnonymous() {
|
||||
get isAnonymous(): Boolean {
|
||||
return !this._valueOrNull('email') && this._valueOrNull('providerId') === 'firebase';
|
||||
}
|
||||
|
||||
get photoURL() {
|
||||
get photoURL(): String|null {
|
||||
return this._valueOrNull('photoURL');
|
||||
}
|
||||
|
||||
// TODO no RN android method yet, the SDK does have .getProviderData but returns as a List.
|
||||
// get providerData() {
|
||||
// return this._valueOrNull('providerData');
|
||||
// }
|
||||
|
||||
get providerId() {
|
||||
return this._valueOrNull('providerId');
|
||||
}
|
||||
|
||||
// TODO no android method
|
||||
// get refreshToken() {
|
||||
// return this._valueOrNull('refreshToken');
|
||||
// }
|
||||
|
||||
get uid() {
|
||||
get uid(): String {
|
||||
return this._valueOrNull('uid');
|
||||
}
|
||||
|
||||
|
@ -109,40 +100,83 @@ export default class User {
|
|||
};
|
||||
}
|
||||
|
||||
delete(...args) {
|
||||
return this._auth.deleteUser(...args);
|
||||
/**
|
||||
* Delete the current user
|
||||
* @return {Promise}
|
||||
*/
|
||||
delete(): Promise<Object> {
|
||||
return promisify('delete', FirebaseAuth, 'auth/')();
|
||||
}
|
||||
|
||||
reload(...args) {
|
||||
return this._auth.reloadUser(...args);
|
||||
/**
|
||||
* Reload the current user
|
||||
* @return {Promise}
|
||||
*/
|
||||
reload(): Promise<Object> {
|
||||
return promisify('reload', FirebaseAuth, 'auth/')();
|
||||
}
|
||||
|
||||
// TODO valueOrNul token - optional promise
|
||||
getToken(...args) {
|
||||
return this._auth.getToken(...args);
|
||||
// TODO no RN android method yet, the SDK does have .getProviderData but returns as a List.
|
||||
// get providerData() {
|
||||
// return this._valueOrNull('providerData');
|
||||
// }
|
||||
|
||||
/**
|
||||
* Re-authenticate a user with a third-party authentication provider
|
||||
* @return {Promise} A promise resolved upon completion
|
||||
*/
|
||||
reauthenticate(credential: CredentialType): Promise<Object> {
|
||||
return promisify('reauthenticate', FirebaseAuth, 'auth/')(credential.provider, credential.token, credential.secret);
|
||||
}
|
||||
|
||||
get reauthenticate() {
|
||||
return this._auth.reauthenticateUser;
|
||||
/**
|
||||
* get the token of current user
|
||||
* @return {Promise}
|
||||
*/
|
||||
getToken(): Promise<Object> {
|
||||
return promisify('getToken', FirebaseAuth, 'auth/')();
|
||||
}
|
||||
|
||||
// TODO match errors to auth/something errors from firebase web api
|
||||
get updateEmail() {
|
||||
if (this.isAnonymous) return () => Promise.reject(new Error('Can not update email on an anonymous user.'));
|
||||
return this._auth.updateEmail;
|
||||
/**
|
||||
*
|
||||
* @param credential
|
||||
*/
|
||||
link(credential: CredentialType) {
|
||||
return promisify('link', FirebaseAuth, 'auth/')(credential.provider, credential.token, credential.secret);
|
||||
}
|
||||
|
||||
get updateProfile() {
|
||||
return this._auth.updateProfile;
|
||||
|
||||
/**
|
||||
* Update the current user's email
|
||||
* @param {string} email The user's _new_ email
|
||||
* @return {Promise} A promise resolved upon completion
|
||||
*/
|
||||
updateEmail(email: string): Promise<Object> {
|
||||
return promisify('updateUserEmail', FirebaseAuth, 'auth/')(email);
|
||||
}
|
||||
|
||||
get updatePassword() {
|
||||
if (this.isAnonymous) return () => Promise.reject(new Error('Can not update password on an anonymous user.'));
|
||||
return this._auth.updatePassword;
|
||||
/**
|
||||
* Update the current user's profile
|
||||
* @param {Object} updates An object containing the keys listed [here](https://firebase.google.com/docs/auth/ios/manage-users#update_a_users_profile)
|
||||
* @return {Promise}
|
||||
*/
|
||||
updateProfile(updates: Object = {}): Promise<Object> {
|
||||
return promisify('updateUserProfile', FirebaseAuth, 'auth/')(updates);
|
||||
}
|
||||
|
||||
get sendEmailVerification() {
|
||||
if (this.isAnonymous) return () => Promise.reject(new Error('Can not verify email on an anonymous user.'));
|
||||
return this._auth.sendEmailVerification;
|
||||
/**
|
||||
* Update the current user's password
|
||||
* @param {string} password the new password
|
||||
* @return {Promise}
|
||||
*/
|
||||
updatePassword(password: string): Promise<Object> {
|
||||
return promisify('updateUserPassword', FirebaseAuth, 'auth/')(password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send verification email to current user.
|
||||
*/
|
||||
sendEmailVerification(): Promise<Object> {
|
||||
return promisify('sendEmailVerification', FirebaseAuth, 'auth/')();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue