Curlas
Curlas

Reputation: 899

Cordova firebase google auth

I'm trying to implement Google Auth in a cordova (phonegap) app.

https://firebase.google.com/docs/auth/web/cordova?hl=en-419

My login method:

var provider = new firebase.auth.GoogleAuthProvider();
firebase.auth().signInWithRedirect(provider).then(function() {
                console.log("hola");
                return firebase.auth().getRedirectResult();
}).then(function(result) {
                // This gives you a Google Access Token.
                // You can use it to access the Google API.
                var token = result.credential.accessToken;
                // The signed-in user info.
                var user = result.user;
                afterLoginGoogle(user);
}).catch(function(error) {
                // Handle Errors here.
                var errorCode = error.code;
                var errorMessage = error.message;
                console.log("error1 "+ errorMessage);   //Error log!!!!

            });
});

When I execute my login method, a new chrome tab is launched, and I put my google user and password. Then, tab is closed and app is showed again, but I allways get an error in my console: "error1 the redirect operation has been cancelled by the user before finalizing."

the first time I got this error I put this code when the app loads:

firebase.auth().getRedirectResult().then(function(result) {
        if (result.credential) {
        // This gives you a Google Access Token.
        // You can use it to access the Google API.
        var token = result.credential.accessToken;
        // The signed-in user info.
        var user = result.user;
        // ...
        console.log("Despues");
        afterLoginGoogle(user);
        }
    }).catch(function(error) {
        // Handle Errors here.
        var errorCode = error.code;
        var errorMessage = error.message;
        console.log("Despues"+errorMessage);
    });

I've tried catch all Dinamic links events,to test, but no event is recieved:

universalLinks.subscribe(null, function(eventData) {
            alert('Did launch application from the link: ' + eventData.url);
});

but it never run :(

Can anyone help me please. I'm exausted whith this situation.

Upvotes: 2

Views: 2362

Answers (2)

Curlas
Curlas

Reputation: 899

I'm going to post an answer to my own question, because it can be usefull for other people.

First time, if yoy follow the guide https://firebase.google.com/docs/auth/web/cordova?hl=en-419 , it works. But...

Cordova universal link plugin has an issue whith newest cordova versions, not solved yet: https://github.com/nordnet/cordova-universal-links-plugin/issues/133

You can fix the plugin manually: In this file: ./plugins/cordova-universal-links-plugin/hooks/lib/android/manifestWriter.js change at line 21:

var pathToManifest = path.join(cordovaContext.opts.projectRoot, 'platforms', 'android', 'AndroidManifest.xml');

to:

var pathToManifest = path.join(
    cordovaContext.opts.projectRoot,
    'platforms',
    'android',
    'app',
    'src',
    'main',
    'AndroidManifest.xml');

And, if you are having problems with universal links, take a look to the manifest resulting file: platforms/android/app/src/main/AndroidManifest.xml

  <intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data android:host="XXXXXXX.page.link" android:scheme="https"/>
  </intent-filter>
  <intent-filter android:autoVerify="true">
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data android:host="XXXXXXXXX.firebaseapp.com" android:scheme="https" android:path="/__/auth/callback"/>
  </intent-filter>

And check if this configuration it's equivalentu whith your config.xml. You must not change Manifest file!!! It's only for check it. If not, check if you have more than one annotation about universal links in the config.xml.

Upvotes: 6

Chris Underdown
Chris Underdown

Reputation: 1829

Was anyone successfully able to authenticate users after the redirect? I get nothing back from the DL Event Listeners and a Firebbase Error: The redirect operation has been cancelled by the user before finalizing.

Upvotes: 0

Related Questions