Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 2d9dc6d

Browse files
committed
Api to unlink a provider
1 parent 2058121 commit 2d9dc6d

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

docs/AUTHENTICATION.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,17 @@ Shouldn't be more complicated than:
639639
```
640640
</details>
641641

642+
### unlinking provider
643+
For a given user, and a given provider ("google.com","password",...)
644+
645+
<details>
646+
<summary>Native API</summary>
647+
648+
```js
649+
user.unlink(providerId);
650+
```
651+
</details>
652+
642653
### reauthenticate
643654
Some security-sensitive actions (deleting an account, changing a password) require that the user has recently signed in.
644655
If you perform one of these actions, and the user signed in too long ago, the action fails.

src/firebase.android.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,30 @@ firebase.logout = arg => {
663663
});
664664
};
665665

666+
firebase.unlink = providerId => {
667+
return new Promise((resolve, reject) => {
668+
try {
669+
const user = com.google.firebase.auth.FirebaseAuth.getInstance().getCurrentUser();
670+
if (!user) {
671+
resolve();
672+
}
673+
user.unlink(providerId).addOnCompleteListener(new com.google.android.gms.tasks.OnCompleteListener({
674+
onComplete: task => {
675+
if (task.isSuccessful()) {
676+
resolve();
677+
} else {
678+
reject((task.getException() && task.getException().getReason ? task.getException().getReason() : task.getException()));
679+
}
680+
}
681+
})
682+
);
683+
} catch (ex) {
684+
console.log("Error in firebase.unlink: " + ex);
685+
reject(ex);
686+
}
687+
});
688+
};
689+
666690
firebase.getAuthToken = arg => {
667691
return new Promise((resolve, reject) => {
668692
try {

src/firebase.ios.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,26 @@ firebase.logout = arg => {
590590
});
591591
};
592592

593+
firebase.unlink = providerId => {
594+
return new Promise((resolve, reject) => {
595+
try {
596+
const user = FIRAuth.auth().currentUser;
597+
598+
user.unlinkFromProviderCompletion(providerId, (user, error) => {
599+
if (error) {
600+
reject(error.localizedDescription);
601+
} else {
602+
resolve(user);
603+
}
604+
});
605+
606+
} catch (ex) {
607+
console.log("Error in firebase.logout: " + ex);
608+
reject(ex);
609+
}
610+
});
611+
};
612+
593613
function toLoginResult(user, additionalUserInfo?: FIRAdditionalUserInfo): User {
594614
if (!user) {
595615
return null;

0 commit comments

Comments
 (0)