Googe登录无法在离子型Android应用程序中运行,当我运行ionic serve
时,在Web应用程序中可以正常运行。
应用程序模块:
const firebaseConfig = {
// fire base config here copied from the console.
};
@NgModule({
declarations: [MyApp, AboutPage, ContactPage, HomePage, TabsPage],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
AngularFireModule.initializeApp(firebaseConfig),
AngularFireAuthModule,
ComponentsModule
],
bootstrap: [IonicApp],
entryComponents: [MyApp, AboutPage, ContactPage, HomePage, TabsPage],
providers: [
StatusBar,
SplashScreen,
{ provide: ErrorHandler, useClass: IonicErrorHandler }
]
})
export class AppModule {}
我已经安装了cordova-support-google-services
软件包并添加了google-services.json
文件,该文件是从firebase
控制台下载的,并将其放在platforms/android/app/
目录中。
@Injectable({ providedIn: "root" })
export class AuthService {
user$: Observable<User>;
constructor(
private afAuth: AngularFireAuth,
private afs: AngularFirestore,
private router: Router
) {
this.user$ = this.afAuth.authState.pipe(
switchMap(user => {
// Logged in
if (user) {
return this.afs.doc<User>(`users/${user.uid}`).valueChanges();
} else {
// Logged out
return of(null);
}
})
);
}
async googleSignin() {
const provider = new auth.GoogleAuthProvider();
const credential = await this.afAuth.auth.signInWithPopup(provider);
return this.updateUserData(credential.user);
}
private updateUserData(user) {
// Sets user data to firestore on login
const userRef: AngularFirestoreDocument<User> = this.afs.doc(
`users/${user.uid}`
);
const data = {
uid: user.uid,
email: user.email,
displayName: user.displayName,
photoURL: user.photoURL
};
return userRef.set(data, { merge: true });
}
async signOut() {
await this.afAuth.auth.signOut();
this.router.navigate(["/"]);
}
}
上面的代码在网络上工作正常,但在android上无法正常工作。单击按钮后,将在chrome浏览器中打开新标签页,并显示google登录信息,成功登录后将显示白色空白页面,未重定向到应用程序,而且在firebase控制台中,我看到用户未通过身份验证。 / p>