From 5ae0f96e42b883896fe29b825781d0bce05d0045 Mon Sep 17 00:00:00 2001 From: EddyVerbruggen Date: Fri, 21 Dec 2018 13:21:31 +0100 Subject: [PATCH] Api to unlink a provider #995 --- docs/AUTHENTICATION.md | 14 +++++++++++++- src/app/auth/index.ts | 16 ++++++++++++++++ src/firebase.android.ts | 25 ++++++++++++++----------- src/firebase.d.ts | 2 ++ src/firebase.ios.ts | 4 ++++ 5 files changed, 49 insertions(+), 12 deletions(-) diff --git a/docs/AUTHENTICATION.md b/docs/AUTHENTICATION.md index 7b8f1470..eff65158 100644 --- a/docs/AUTHENTICATION.md +++ b/docs/AUTHENTICATION.md @@ -649,7 +649,19 @@ For a given user, and a given provider ("google.com","password",...) Native API ```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))); +``` + + +
+ Web API + +```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))); ```
diff --git a/src/app/auth/index.ts b/src/app/auth/index.ts index cc432149..5f807338 100644 --- a/src/app/auth/index.ts +++ b/src/app/auth/index.ts @@ -28,6 +28,22 @@ export module auth { }); } + public unlink(providerId: string): Promise { + 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 { return new Promise((resolve, reject) => { firebase.login({ diff --git a/src/firebase.android.ts b/src/firebase.android.ts index 1ee6cf0d..6c7f927b 100755 --- a/src/firebase.android.ts +++ b/src/firebase.android.ts @@ -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); diff --git a/src/firebase.d.ts b/src/firebase.d.ts index 6a52588a..1e0cc07c 100644 --- a/src/firebase.d.ts +++ b/src/firebase.d.ts @@ -849,6 +849,8 @@ export function getAuthToken(option: GetAuthTokenOptions): Promise; export function logout(): Promise; +export function unlink(providerId: string): Promise; + export function fetchProvidersForEmail(email: string): Promise>; export function fetchSignInMethodsForEmail(email: string): Promise>; diff --git a/src/firebase.ios.ts b/src/firebase.ios.ts index 982fac02..05bc96f2 100755 --- a/src/firebase.ios.ts +++ b/src/firebase.ios.ts @@ -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) {