[auth] Some flow types and tidy up

This commit is contained in:
Chris Bianca
2018-01-18 09:49:11 +00:00
parent 285e31df65
commit a0de480fc7
4 changed files with 34 additions and 21 deletions

View File

@@ -942,7 +942,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
* @param promise
*/
@ReactMethod
public void link(String appName, String provider, String authToken, String authSecret, final Promise promise) {
public void linkWithCredential(String appName, String provider, String authToken, String authSecret, final Promise promise) {
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);
@@ -1010,7 +1010,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
}
/**
* reauthenticate
* reauthenticateWithCredential
*
* @param provider
* @param authToken
@@ -1018,7 +1018,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
* @param promise
*/
@ReactMethod
public void reauthenticate(String appName, String provider, String authToken, String authSecret, final Promise promise) {
public void reauthenticateWithCredential(String appName, String provider, String authToken, String authSecret, final Promise promise) {
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
final FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);

View File

@@ -727,7 +727,7 @@ RCT_EXPORT_METHOD(_confirmVerificationCode:(NSString *) appDisplayName
@param RCTPromiseRejectBlock reject
@return
*/
RCT_EXPORT_METHOD(link:
RCT_EXPORT_METHOD(linkWithCredential:
(NSString *) appDisplayName
provider:
(NSString *) provider
@@ -797,7 +797,7 @@ RCT_EXPORT_METHOD(unlink:
}
/**
reauthenticate
reauthenticateWithCredential
@param NSString provider
@param NSString authToken
@@ -806,7 +806,7 @@ RCT_EXPORT_METHOD(unlink:
@param RCTPromiseRejectBlock reject
@return
*/
RCT_EXPORT_METHOD(reauthenticate:
RCT_EXPORT_METHOD(reauthenticateWithCredential:
(NSString *) appDisplayName
provider:
(NSString *) provider

View File

@@ -29,6 +29,11 @@ type UserInfo = {
uid: string,
}
type UpdateProfile = {
displayName?: string,
photoURL?: string,
}
export default class User {
_auth: Auth;
_user: NativeUser;
@@ -104,13 +109,23 @@ export default class User {
return getNativeModule(this._auth).getToken(forceRefresh);
}
/**
* get the token of current user
* @deprecated Deprecated getToken in favor of getIdToken.
* @return {Promise}
*/
getToken(forceRefresh: boolean = false): Promise<Object> {
console.warn('Deprecated firebase.User.prototype.getToken in favor of firebase.User.prototype.getIdToken.');
return getNativeModule(this._auth).getToken(forceRefresh);
}
/**
*
* @param credential
*/
linkWithCredential(credential: AuthCredential): Promise<User> {
return this._auth
._interceptUserValue(getNativeModule(this._auth).link(credential.providerId, credential.token, credential.secret));
._interceptUserValue(getNativeModule(this._auth).linkWithCredential(credential.providerId, credential.token, credential.secret));
}
/**
@@ -119,7 +134,7 @@ export default class User {
*/
reauthenticateWithCredential(credential: AuthCredential): Promise<void> {
return this._auth
._interceptUndefinedUserValue(getNativeModule(this._auth).reauthenticate(credential.providerId, credential.token, credential.secret));
._interceptUndefinedUserValue(getNativeModule(this._auth).reauthenticateWithCredential(credential.providerId, credential.token, credential.secret));
}
/**
@@ -178,21 +193,11 @@ export default class User {
* @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<void> {
updateProfile(updates: UpdateProfile = {}): Promise<void> {
return this._auth
._interceptUndefinedUserValue(getNativeModule(this._auth).updateProfile(updates));
}
/**
* get the token of current user
* @deprecated Deprecated getToken in favor of getIdToken.
* @return {Promise}
*/
getToken(forceRefresh: boolean = false): Promise<Object> {
console.warn('Deprecated firebase.User.prototype.getToken in favor of firebase.User.prototype.getIdToken.');
return getNativeModule(this._auth).getToken(forceRefresh);
}
/**
* KNOWN UNSUPPORTED METHODS
*/

View File

@@ -28,6 +28,14 @@ type AuthResult = {
user: Object|null
} | null;
type ActionCodeInfo = {
data: {
email?: string,
fromEmail?: string,
},
operation: 'PASSWORD_RESET' | 'VERIFY_EMAIL' | 'RECOVER_EMAIL',
}
const NATIVE_EVENTS = [
'auth_state_changed',
'phone_auth_state_changed',
@@ -315,7 +323,7 @@ export default class Auth extends ModuleBase {
* @param code
* @return {Promise.<any>|Promise<ActionCodeInfo>}
*/
checkActionCode(code: string): Promise<void> {
checkActionCode(code: string): Promise<ActionCodeInfo> {
return getNativeModule(this).checkActionCode(code);
}
@@ -323,7 +331,7 @@ export default class Auth extends ModuleBase {
* Returns a list of authentication providers that can be used to sign in a given user (identified by its main email address).
* @return {Promise}
*/
fetchProvidersForEmail(email: string): Promise<Array<String>> {
fetchProvidersForEmail(email: string): Promise<String[]> {
return getNativeModule(this).fetchProvidersForEmail(email);
}