我在 firebase 身份验证和 google 提供商方面遇到了一些麻烦。我尝试使用谷歌提供商登录(这工作正常),但后来我想重定向到我的主页,但我遇到了问题。
我有一个身份验证提供者:
import { Injectable } from '@angular/core';
import firebase from 'firebase';
@Injectable()
export class AuthData {
// Here we declare the variables we'll be using.
public fireAuth: any;
googleProvider: any;
constructor() {
this.fireAuth = firebase.auth(); // We are creating an auth reference.
// Google Provider for Google Auth
this.googleProvider = new firebase.auth.GoogleAuthProvider();
}
/**
* This function doesn't take any params, it just logs the current user out of the app.
*/
logoutUser(): any {
return this.fireAuth.signOut();
}
/**
* This function doesn't take any params, it just signin the current user
* using google provider.
*/
googleSignin(): any {
return this.fireAuth.signInWithRedirect(this.googleProvider);
}
}
这是我的应用程序组件:
[all imports here]
@Component({
templateUrl: 'app.html'
})
export class MyApp {
@ViewChild(Nav) nav: Nav;
rootPage: any = Home;
constructor(public platform: Platform) {
this.initializeApp();
}
initializeApp() {
firebase.initializeApp(FirebaseConfig);
firebase.auth().onAuthStateChanged((user) => {
if (!user) {
this.nav.setRoot(Home);
} else {
this.nav.setRoot(Menu);
}
});
this.platform.ready().then(() => {
StatusBar.styleDefault();
});
}
}
这是我的家.ts:
[some imports here]
@Component({
templateUrl: 'home.html',
})
export class Home {
constructor(public navCtrl: NavController, public authData: AuthData) {}
registerUserWithGoogle() {
this.authData.googleSignin();
}
}
因此,当我尝试从 home.html(它是 app.html 上的视图)登录到 menu.html 时,我遇到了一些奇怪的行为。我有一些截图。
应用程序.html:
<ion-nav [root]="rootPage" #content swipeBackEnabled="false"></ion-nav>
主页.html:
<ion-content class="home">
<div class="logo">
<div class="logo-icon">
<img src="assets/img/logotipo.png" alt="">
</div>
</div>
<button ion-button block color="danger" class="google-btn" (click)="registerUserWithGoogle()">
Log In with Google
</button>
</ion-content>
这是我登录时得到的信息:
如果我点击箭头我会得到这个:
但现在我无法单击侧面菜单,我不知道它是否用于嵌套两个离子视图或其他内容。
谢谢