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

Commit 2262b09

Browse files
Merge pull request #995 from vratojr/master
Api to unlink a provider
2 parents 3674371 + d377afa commit 2262b09

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
@@ -642,6 +642,17 @@ Shouldn't be more complicated than:
642642
```
643643
</details>
644644

645+
### unlinking provider
646+
For a given user, and a given provider ("google.com","password",...)
647+
648+
<details>
649+
<summary>Native API</summary>
650+
651+
```js
652+
user.unlink(providerId);
653+
```
654+
</details>
655+
645656
### reauthenticate
646657
Some security-sensitive actions (deleting an account, changing a password) require that the user has recently signed in.
647658
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
@@ -661,6 +661,30 @@ firebase.logout = arg => {
661661
});
662662
};
663663

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

src/firebase.ios.ts

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

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

0 commit comments

Comments
 (0)