This commit is contained in:
Salakar 2017-07-17 17:35:16 +01:00
commit ef259fbbc0
4 changed files with 71 additions and 4 deletions

View File

@ -719,6 +719,38 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
}
}
/**
* unlink
*
* @url https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseUser.html#unlink(java.lang.String)
* @param providerId
* @param promise
*/
@ReactMethod
public void unlink(final String providerId, final Promise promise) {
FirebaseUser user = mAuth.getCurrentUser();
Log.d(TAG, "unlink");
if (user != null) {
user.unlink(providerId)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Log.d(TAG, "unlink:onComplete:success");
promiseWithUser(task.getResult().getUser(), promise);
} else {
Exception exception = task.getException();
Log.e(TAG, "unlink:onComplete:failure", exception);
promiseRejectAuthException(promise, exception);
}
}
});
} else {
promiseNoUser(promise, true);
}
}
/**
* reauthenticate
*

View File

@ -621,6 +621,32 @@ RCT_EXPORT_METHOD(link:(NSString *) appName
}
}
/**
unlink
@param NSString provider
@param NSString authToken
@param NSString authSecret
@param RCTPromiseResolveBlock resolve
@param RCTPromiseRejectBlock reject
@return
*/
RCT_EXPORT_METHOD(unlink:(NSString *)providerId resolver:(RCTPromiseResolveBlock) resolve rejecter:(RCTPromiseRejectBlock) reject) {
FIRUser *user = [FIRAuth auth].currentUser;
if (user) {
[user unlinkFromProvider:providerId completion:^(FIRUser *_Nullable _user, NSError *_Nullable error) {
if (error) {
[self promiseRejectAuthException:reject error:error];
} else {
[self promiseWithUser:resolve rejecter:reject user:_user];
}
}];
} else {
[self promiseNoUser:resolve rejecter:reject isError:YES];
}
}
/**
reauthenticate

View File

@ -112,6 +112,15 @@ export default class User {
return this._auth._interceptUserValue(this._auth._native.link(credential.provider, credential.token, credential.secret));
}
/**
*
* @param providerId
* @return {Promise.<TResult>|*}
*/
unlink(providerId: string) {
return this._auth._interceptUserValue(FirebaseAuth.unlink(providerId));
}
/**
* Re-authenticate a user with a third-party authentication provider
* @return {Promise} A promise resolved upon completion

View File

@ -1,6 +1,6 @@
{
"name": "react-native-firebase",
"version": "2.0.2",
"version": "2.0.3",
"author": "Invertase <contact@invertase.io> (http://invertase.io)",
"description": "A well tested, feature rich Firebase implementation for React Native, supporting iOS & Android. Individual module support for Auth, Database, Messaging, Remote Config, Storage, Admob, Analytics, Crash Reporting, and Performance.",
"main": "index",