BHAR4T
BHAR4T

Reputation: 334

Convert cordova-plugin-firebase-authentication auth to Firebase JS-SDK auth

I am using mobile verification authentication by cordova plugin cordova-plugin-firebase-authentication. The plugin is working fine, I can login, logout everything, which this defined in their documentation.

With this plugin I am using Firebase JS-SDK for firestore, As I am using third party authentication mechanism the firebase defined onAuthStateChanged is not working and it is obvious, and because of this onAuthStateChanged gives null for auth user.

I want to convert cordova-plugin-firebase-authentication auth user to firebase js-sdk auth user, or how can I use cordova-plugin-firebase-authentication auth user request.auth.uid in firebase security rules.

Upvotes: 2

Views: 742

Answers (1)

BHAR4T
BHAR4T

Reputation: 334

Use cordova-plugin-firebase-authentication just for sending OTP by given method

cordova.plugins.firebase.auth
  .verifyPhoneNumber("+123456789", 30000)
  .then(function(verificationId) {
      // pass verificationId to signInWithVerificationId
  });

instead of using cordova-plugin-firebase-authentication cordova.plugins.firebase.auth.signInWithVerificationId("djgfioerjg34", "123456"); for OTP verification, use firebase-js-sdk methods:

var credential = firebase.auth.PhoneAuthProvider.credential(verificationIdGeneratedByCordovaPlugin, OTP);

Then, you can sign in the user with the credential:

firebase.auth().signInWithCredential(credential);

Upvotes: 2

Related Questions