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

Commit

Permalink
Merge pull request #995 from vratojr/master
Browse files Browse the repository at this point in the history
Api to unlink a provider
  • Loading branch information
EddyVerbruggen authored Dec 21, 2018
2 parents 3674371 + d377afa commit 2262b09
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/AUTHENTICATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,17 @@ Shouldn't be more complicated than:
```
</details>

### unlinking provider
For a given user, and a given provider ("google.com","password",...)

<details>
<summary>Native API</summary>

```js
user.unlink(providerId);
```
</details>

### reauthenticate
Some security-sensitive actions (deleting an account, changing a password) require that the user has recently signed in.
If you perform one of these actions, and the user signed in too long ago, the action fails.
Expand Down
24 changes: 24 additions & 0 deletions src/firebase.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,30 @@ firebase.logout = arg => {
});
};

firebase.unlink = providerId => {
return new Promise((resolve, reject) => {
try {
const user = com.google.firebase.auth.FirebaseAuth.getInstance().getCurrentUser();
if (!user) {
resolve();
}
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);
}
});
};

firebase.getAuthToken = arg => {
return new Promise((resolve, reject) => {
try {
Expand Down
20 changes: 20 additions & 0 deletions src/firebase.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,26 @@ firebase.logout = arg => {
});
};

firebase.unlink = providerId => {
return new Promise((resolve, reject) => {
try {
const user = FIRAuth.auth().currentUser;

user.unlinkFromProviderCompletion(providerId, (user, error) => {
if (error) {
reject(error.localizedDescription);
} else {
resolve(user);
}
});

} catch (ex) {
console.log("Error in firebase.logout: " + ex);
reject(ex);
}
});
};

function toLoginResult(user, additionalUserInfo?: FIRAdditionalUserInfo): User {
if (!user) {
return null;
Expand Down

0 comments on commit 2262b09

Please sign in to comment.