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

Commit

Permalink
Api to unlink a provider #995
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Dec 21, 2018
1 parent 2262b09 commit 5ae0f96
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 12 deletions.
14 changes: 13 additions & 1 deletion docs/AUTHENTICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,19 @@ For a given user, and a given provider ("google.com","password",...)
<summary>Native API</summary>

```js
user.unlink(providerId);
user.unlink(providerId /* string */)
.then(user => console.log("Unlink OK, user: " + JSON.stringify(user)))
.catch(error => console.log("Unlink error: " + JSON.stringify(error)));
```
</details>

<details>
<summary>Web API</summary>

```js
firebaseWebApi.auth().unlink(providerId /* string */)
.then(user => console.log("Unlink OK, user: " + JSON.stringify(user)))
.catch(error => console.log("Unlink error: " + JSON.stringify(error)));
```
</details>

Expand Down
16 changes: 16 additions & 0 deletions src/app/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ export module auth {
});
}

public unlink(providerId: string): Promise<any> {
return new Promise((resolve, reject) => {
firebase.unlink(providerId)
.then(user => {
this.currentUser = user;
resolve(user);
})
.catch(err => {
reject({
// code: "",
message: err
});
});
});
}

public signInWithEmailAndPassword(email: string, password: string): Promise<any> {
return new Promise((resolve, reject) => {
firebase.login({
Expand Down
25 changes: 14 additions & 11 deletions src/firebase.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,18 +666,21 @@ firebase.unlink = providerId => {
try {
const user = com.google.firebase.auth.FirebaseAuth.getInstance().getCurrentUser();
if (!user) {
resolve();
reject("Not logged in");
return;
}
user.unlink(providerId).addOnCompleteListener(new com.google.android.gms.tasks.OnCompleteListener({
onComplete: task => {
if (task.isSuccessful()) {
resolve();
} else {
reject((task.getException() && task.getException().getReason ? task.getException().getReason() : task.getException()));
}
}
})
);

user.unlink(providerId)
.addOnCompleteListener(new com.google.android.gms.tasks.OnCompleteListener({
onComplete: task => {
if (task.isSuccessful()) {
resolve();
} else {
reject((task.getException() && task.getException().getReason ? task.getException().getReason() : task.getException()));
}
}
})
);
} catch (ex) {
console.log("Error in firebase.unlink: " + ex);
reject(ex);
Expand Down
2 changes: 2 additions & 0 deletions src/firebase.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,8 @@ export function getAuthToken(option: GetAuthTokenOptions): Promise<string>;

export function logout(): Promise<any>;

export function unlink(providerId: string): Promise<User>;

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

export function fetchSignInMethodsForEmail(email: string): Promise<Array<string>>;
Expand Down
4 changes: 4 additions & 0 deletions src/firebase.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,10 @@ firebase.unlink = providerId => {
return new Promise((resolve, reject) => {
try {
const user = FIRAuth.auth().currentUser;
if (!user) {
reject("Not logged in");
return;
}

user.unlinkFromProviderCompletion(providerId, (user, error) => {
if (error) {
Expand Down

0 comments on commit 5ae0f96

Please sign in to comment.