[android][auth] implemented missing 'unlink' method

This commit is contained in:
Salakar 2017-07-12 16:26:02 +01:00
parent 0898f0913d
commit 97447dab5e
3 changed files with 70 additions and 3 deletions

View File

@ -643,6 +643,38 @@ public 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

@ -478,6 +478,32 @@ RCT_EXPORT_METHOD(link:(NSString *)provider authToken:(NSString *)authToken auth
}
}
/**
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

@ -64,11 +64,11 @@ export default class User {
* PROPERTIES
*/
get displayName(): String|null {
get displayName(): String | null {
return this._valueOrNull('displayName');
}
get email(): String|null {
get email(): String | null {
return this._valueOrNull('email');
}
@ -80,7 +80,7 @@ export default class User {
return this._valueOrFalse('isAnonymous');
}
get photoURL(): String|null {
get photoURL(): String | null {
return this._valueOrNull('photoURL');
}
@ -117,6 +117,15 @@ export default class User {
return this._auth._interceptUserValue(FirebaseAuth.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