hholtij hholtij - 2 months ago 59
Android Question

Firebase 3 with ionic 2 google authentication

I am new to mobile app development and ionic 2. I get the google authentication working fine for a web app using angularfire2 but that doesn't work on a mobile device (yet?).
I am using ionic 2 version 2.0.0-beta.35 and firebase 3.2.1

Searching led me to the understanding that for the time being I need to use the google+ plugin for cordova, which I have installed.

I am trying this method in my ts code:

return Observable.create(observer =>
// note for iOS the googleplus plugin requires ENABLE_BITCODE to be turned off in the Xcode
'scopes': 'profile email', // optional, space-separated list of scopes, If not included or empty, defaults to `profile` and `email`.
'webClientId': '_google_client_app_id_.apps.googleusercontent.com',
'offline': true, // optional, but requires the webClientId - if set to true the plugin will also return a serverAuthCode, which can be used to grant offline access to a non-Google server
function (authData)
console.log('got google auth data:', JSON.stringify(authData, null, 2));
let provider = firebase.auth.GoogleAuthProvider.credential(authData.idToken, authData.accessToken);
firebase.auth().signInWithCredential(provider).then((success) =>
console.log('success!', JSON.stringify(success, null, 2));
}, (error) =>
console.log('error', JSON.stringify(error, null, 2))
function (msg)
this.error = msg;

But the compiler keeps complaining about two things:
1. window.plugins is unknown. How can I convince ts that it's there?

  1. There is no
    on the
    object. Searching yielded this link: firebase docs which says there was a method
    , which is not recognized either.

seem to be fine.
itself is recognized.

How can I fix this?


Actually, this is a bug in the typescript definitions. The Firebase team has been notified and is working on a fix. In the meantime use the following workaround:

(<any> firebase.auth.GoogleAuthProvider).credential