chemerisuk / cordova-plugin-firebase-authentication

Cordova plugin for Firebase Authentication
MIT License
98 stars 60 forks source link

Question: pass java "credential" back to js #23

Open hirbod opened 6 years ago

hirbod commented 6 years ago

Hi,

this might be a weird question, but I need to know if there is any chance to pass https://github.com/chemerisuk/cordova-plugin-firebase-authentication/blob/master/src/android/FirebaseAuthenticationPlugin.java#L227

"credential" back to the app? It's not a problem for me to implement a pluginResult, I already tried that, but passing back "credential" isn't any JSON object or something, its something like "com.google.firebnase...@XXXX".

Some JavaInstance or Object I guess. You might ask why I would ever need that: simple; due to Instantverifications and Auto-retrival, my app has a unhandled case (I did not use your plugin, I used a mix from other plugins) and build a credential with the JS-SDK. But this requires a "verificationId", which won't be passed back, as "onCodeSent" won't trigger if there was any instant-verification or auto-retrieval. "credential" only has getProvider() and getSmsCode() - which is useless for me, as getSmsCode can also be null.

I just want to know if you have any idea how to get a working "credential" (maybe as string) so I can just

        // generate credential object with ID from last page and newly entered code
        var credential = firebase.auth.PhoneAuthProvider.credential(
            params.verificationId,
            $scope.code
        );

or REPLACE the "credential" which I have to pass for the JS-SDK. Maybe there is an internal API which still can deliver the verificationId even on instant/auto-retrieval?)

Im not a native speaker, I hope I could make myself clear enough. Currently, my app relies on the js-sdk, I don't have any chance to change my code to 100% incorporate your awesome plugin (as I also do need to upload images and using store-functions, which requires a js-auth)

Would love to donate some $ if you can help me on this.

cairin commented 6 years ago

Try this:

const firebaseAuth = cordova.plugins.firebase.auth;
firebaseAuth.verifyPhoneNumber(phoneNumber, 0).then((verificationId) => {
      // Do what you want with your verificationId
}).catch(reject);

See #37 for explanation.