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

Commit 5ae0f96

Browse files
Api to unlink a provider #995
1 parent 2262b09 commit 5ae0f96

File tree

5 files changed

+49
-12
lines changed

5 files changed

+49
-12
lines changed

docs/AUTHENTICATION.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,19 @@ For a given user, and a given provider ("google.com","password",...)
649649
<summary>Native API</summary>
650650

651651
```js
652-
user.unlink(providerId);
652+
user.unlink(providerId /* string */)
653+
.then(user => console.log("Unlink OK, user: " + JSON.stringify(user)))
654+
.catch(error => console.log("Unlink error: " + JSON.stringify(error)));
655+
```
656+
</details>
657+
658+
<details>
659+
<summary>Web API</summary>
660+
661+
```js
662+
firebaseWebApi.auth().unlink(providerId /* string */)
663+
.then(user => console.log("Unlink OK, user: " + JSON.stringify(user)))
664+
.catch(error => console.log("Unlink error: " + JSON.stringify(error)));
653665
```
654666
</details>
655667

src/app/auth/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ export module auth {
2828
});
2929
}
3030

31+
public unlink(providerId: string): Promise<any> {
32+
return new Promise((resolve, reject) => {
33+
firebase.unlink(providerId)
34+
.then(user => {
35+
this.currentUser = user;
36+
resolve(user);
37+
})
38+
.catch(err => {
39+
reject({
40+
// code: "",
41+
message: err
42+
});
43+
});
44+
});
45+
}
46+
3147
public signInWithEmailAndPassword(email: string, password: string): Promise<any> {
3248
return new Promise((resolve, reject) => {
3349
firebase.login({

src/firebase.android.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -666,18 +666,21 @@ firebase.unlink = providerId => {
666666
try {
667667
const user = com.google.firebase.auth.FirebaseAuth.getInstance().getCurrentUser();
668668
if (!user) {
669-
resolve();
669+
reject("Not logged in");
670+
return;
670671
}
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-
);
672+
673+
user.unlink(providerId)
674+
.addOnCompleteListener(new com.google.android.gms.tasks.OnCompleteListener({
675+
onComplete: task => {
676+
if (task.isSuccessful()) {
677+
resolve();
678+
} else {
679+
reject((task.getException() && task.getException().getReason ? task.getException().getReason() : task.getException()));
680+
}
681+
}
682+
})
683+
);
681684
} catch (ex) {
682685
console.log("Error in firebase.unlink: " + ex);
683686
reject(ex);

src/firebase.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,8 @@ export function getAuthToken(option: GetAuthTokenOptions): Promise<string>;
849849

850850
export function logout(): Promise<any>;
851851

852+
export function unlink(providerId: string): Promise<User>;
853+
852854
export function fetchProvidersForEmail(email: string): Promise<Array<string>>;
853855

854856
export function fetchSignInMethodsForEmail(email: string): Promise<Array<string>>;

src/firebase.ios.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,10 @@ firebase.unlink = providerId => {
595595
return new Promise((resolve, reject) => {
596596
try {
597597
const user = FIRAuth.auth().currentUser;
598+
if (!user) {
599+
reject("Not logged in");
600+
return;
601+
}
598602

599603
user.unlinkFromProviderCompletion(providerId, (user, error) => {
600604
if (error) {

0 commit comments

Comments
 (0)