Ionic 2谷歌登录与火力点
问题描述:
即时通讯与Firebase身份验证和谷歌提供商一些麻烦。我试图用谷歌提供商登录(这工作正常),但然后我想重定向到我的主页,但即时通讯出错了。Ionic 2谷歌登录与火力点
我有一个身份验证提供者:
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);
}
}
这是我app.component:
[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();
});
}
}
这是我home.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的看法)与Google登录到menu.html我有一些奇怪的行为。我有一些截图。
app.html:
<ion-nav [root]="rootPage" #content swipeBackEnabled="false"></ion-nav>
home.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>
这是我所得到的,当我登录:
如果我点击箭头我得到这个:
但现在我不能点击sidemenu,我不知道它是否嵌套两个离子视图或其他东西。
谢谢
答
我读了评论,所以这是现在2部分的问题:
1)对于谷歌验证,该signInWithRedirect()
和signInWithPopUp()
方法不科尔多瓦/离子应用工作尚未 。
你需要使用谷歌原生的插件来获得登录凭据,然后你可以将它们传递到firebase.auth.signInWithCredentials()
2)关于错误发送您的主页:
有一个奇怪的错误在离子的navCtrl未推网页它在用户返回后:
firebase.auth().onAuthStateChanged((user) => {
if (!user) {
this.nav.setRoot(Home);
} else {
this.nav.setRoot(Menu);
}
});
我得到了通过简单的声明rootPage: any = Menu;
,然后做这个,而不是工作:
firebase.auth().onAuthStateChanged((user) => {
if (!user) {
this.nav.setRoot(Home);
}
});
signInWithRedirect和signInWithPopup尚未在离子/科尔多瓦环境中受支持。您必须使用Cordova插件才能登录Google OAuth令牌并使用firebase.auth()。signInWithCredential(firebase.auth.GoogleAccessProvider.credential(null,googleAccessToken))以使用该凭证进行登录。 – bojeil
奥奇谢谢你生病尝试尽快 –
嗨我试试这个https://javebratt.com/firebase-3-email-auth/电子邮件和密码验证,而不是谷歌身份验证,它也一样,所以它可能是应用程序的原因?也许嵌套意见问题? –