即時通訊與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,我不知道它是否嵌套兩個離子視圖或其他東西。
謝謝
signInWithRedirect和signInWithPopup尚未在離子/科爾多瓦環境中受支持。您必須使用Cordova插件才能登錄Google OAuth令牌並使用firebase.auth()。signInWithCredential(firebase.auth.GoogleAccessProvider.credential(null,googleAccessToken))以使用該憑證進行登錄。 – bojeil
奧奇謝謝你生病嘗試儘快 –
嗨我試試這個https://javebratt.com/firebase-3-email-auth/電子郵件和密碼驗證,而不是谷歌身份驗證,它也一樣,所以它可能是應用程序的原因?也許嵌套意見問題? –