Ionic Firebase Google Login


#1

I’m new at App Developing, but I am building an app with a Google Login connected to my Firebase. I can connect and show the user id with success but I want to go to another page (HomePage) when success login.

import { HomePage } from “…/home/home”;
import { RegisterPage } from “…/register/register”;

import * as firebase from “firebase/app”;
import { AngularFireAuth } from “angularfire2/auth”;
import { Observable } from “rxjs/Observable”;
import { Router } from “@angular/router”;

import { GooglePlus } from “@ionic-native/google-plus”;
import { Platform } from “ionic-angular”;

@IonicPage()
@Component({
selector: “page-login”,
templateUrl: “login.html”
})
export class LoginPage {
user: Observable<firebase.User>;

constructor(
public nav: NavController,
public navParams: NavParams,
public forgotCtrl: AlertController,
public menu: MenuController,
public toastCtrl: ToastController,
private afAuth: AngularFireAuth,
private gplus: GooglePlus,
private router: Router,
private platform: Platform
) {
this.menu.swipeEnable(false);
this.user = this.afAuth.authState;
}
async nativeGoogleLogin(): Promise {
try {
const gplusUser = await this.gplus.login({
webClientId:
“MyClientWebAPI”,
offline: true,
scopes: “profile email”
});

  return await this.afAuth.auth.signInWithCredential(
    firebase.auth.GoogleAuthProvider.credential(gplusUser.idToken)

//Here is where i try to inject the router.
.then(success => {
this.router.navigate([“HomePage”]);
})
);
} catch (err) {
console.log(err);
}
}
googleLogin() {
if (this.platform.is(“cordova”)) {
this.nativeGoogleLogin();
} else {
this.webGoogleLogin();
}
}
I tried to inject some code in the auth by using then(success =>…) but I can’t get it to work.

Can anyone help with the code?

Thanks


#2

Have you tried with:

this.nav.setRoot(HomePage);

or

this.nav.push(HomePage);


#3

Ionic 3 and Angularfire2 Auth sample code:

For example:


#4

thanks! That was the route i went.


#5

Thanks for the help me . thanks