From 2d9dc6db016796fb0782fc30f509bd6c63dc8cec Mon Sep 17 00:00:00 2001 From: vratojr Date: Sat, 27 Oct 2018 17:07:29 +0200 Subject: [PATCH 1/3] Api to unlink a provider --- docs/AUTHENTICATION.md | 11 +++++++++++ src/firebase.android.ts | 24 ++++++++++++++++++++++++ src/firebase.ios.ts | 20 ++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/docs/AUTHENTICATION.md b/docs/AUTHENTICATION.md index 618b74ea..1247e1b6 100644 --- a/docs/AUTHENTICATION.md +++ b/docs/AUTHENTICATION.md @@ -639,6 +639,17 @@ Shouldn't be more complicated than: ``` +### unlinking provider +For a given user, and a given provider ("google.com","password",...) + +
+ Native API + +```js + user.unlink(providerId); +``` +
+ ### 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. diff --git a/src/firebase.android.ts b/src/firebase.android.ts index 8883f023..ea95693c 100755 --- a/src/firebase.android.ts +++ b/src/firebase.android.ts @@ -663,6 +663,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 { diff --git a/src/firebase.ios.ts b/src/firebase.ios.ts index 270dd6c3..9166592e 100755 --- a/src/firebase.ios.ts +++ b/src/firebase.ios.ts @@ -590,6 +590,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; From a3b9ac7d9957ff13b07957f838ac38f4a76beebf Mon Sep 17 00:00:00 2001 From: vratojr Date: Sat, 27 Oct 2018 17:14:34 +0200 Subject: [PATCH 2/3] Fixed linting problems and build of demo package --- demo/package.json | 4 ++-- src/firebase.android.ts | 2 +- src/firebase.ios.ts | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/demo/package.json b/demo/package.json index ff81f7d1..23224e65 100644 --- a/demo/package.json +++ b/demo/package.json @@ -10,7 +10,7 @@ }, "dependencies": { "firebase-functions": "^2.0.5", - "nativescript-plugin-firebase": "file:../publish/package/nativescript-plugin-firebase-7.3.0.tgz", + "nativescript-plugin-firebase": "file:../publish/package/nativescript-plugin-firebase-7.3.1.tgz", "nativescript-theme-core": "^1.0.4", "nativescript-unit-test-runner": "^0.3.4", "tns-core-modules": "^4.2.1" @@ -37,4 +37,4 @@ "build.plugin": "cd ../src && npm run build", "ci.tslint": "npm i && tslint --config '../tslint.json' 'app/**/*.ts' --exclude '**/node_modules/**' --exclude '**/typings/**'" } -} \ No newline at end of file +} diff --git a/src/firebase.android.ts b/src/firebase.android.ts index ea95693c..bec87fe5 100755 --- a/src/firebase.android.ts +++ b/src/firebase.android.ts @@ -312,7 +312,7 @@ firebase.init = arg => { const firebaseAuth = com.google.firebase.auth.FirebaseAuth.getInstance(); if (arg.onAuthStateChanged) { - firebase.addAuthStateListener(arg.onAuthStateChanged) + firebase.addAuthStateListener(arg.onAuthStateChanged); } // Listen to auth state changes diff --git a/src/firebase.ios.ts b/src/firebase.ios.ts index 9166592e..dc6939ef 100755 --- a/src/firebase.ios.ts +++ b/src/firebase.ios.ts @@ -1572,18 +1572,18 @@ firebase.firestore.WriteBatch = (nativeWriteBatch: FIRWriteBatch): firestore.Wri fixSpecialFields(data); nativeWriteBatch.setDataForDocumentMerge(data, documentRef.ios, options && options.merge); return this; - }; + } public update = (documentRef: firestore.DocumentReference, data: firestore.UpdateData): firestore.WriteBatch => { fixSpecialFields(data); nativeWriteBatch.updateDataForDocument(data, documentRef.ios); return this; - }; + } public delete = (documentRef: firestore.DocumentReference): firestore.WriteBatch => { nativeWriteBatch.deleteDocument(documentRef.ios); return this; - }; + } commit(): Promise { return new Promise((resolve, reject) => { From d377afa27938b470c47cceb30389e3b89b0cc775 Mon Sep 17 00:00:00 2001 From: Eddy Verbruggen Date: Fri, 21 Dec 2018 12:46:15 +0100 Subject: [PATCH 3/3] Let's avoid a merge conflict --- demo/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/package.json b/demo/package.json index 23224e65..530b91aa 100644 --- a/demo/package.json +++ b/demo/package.json @@ -10,7 +10,7 @@ }, "dependencies": { "firebase-functions": "^2.0.5", - "nativescript-plugin-firebase": "file:../publish/package/nativescript-plugin-firebase-7.3.1.tgz", + "nativescript-plugin-firebase": "file:../publish/package/nativescript-plugin-firebase-7.3.0.tgz", "nativescript-theme-core": "^1.0.4", "nativescript-unit-test-runner": "^0.3.4", "tns-core-modules": "^4.2.1"