Search code examples
ionic-frameworkgoogle-oauthionic2ionic-view

How to implement Google OAuth in an Ionic 2 app?


I need to add Google login in my Ionic v2 app.

Currently I cannot use the Ionic Authentication service because it's not ready for v2 yet.

I've also tried the ng2-cordova-oauth plugin but I cannot use ionic serve or Ionic View to test the authentication which is a huge inconvenience for me because I no longer have an easy way to show the app to the client.

So... any alternative?


Solution

  • Firebase user authentication is an alternative , you can implement google authentification with few lines of code

    var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
    ref.authWithOAuthPopup("google", function(error, authData) {
      if (error) {
        console.log("Login Failed!", error);
      } else {
        console.log("Authenticated successfully with payload:", authData);
      }
    });

    please see the documentation here firebase documentation