简体   繁体   English

离子角+电容器+火力基地。 使用新的 Capacitor 3 和 Firebase 9 帮助迁移 Google 登录代码

[英]Ionic-Angular+capacitor+firebase. Help to migrate Google Sign-in codes with the new Capacitor 3 and Firebase 9

I hope someone can help me how to make this old codes for firebase google sign-in to work in the new capacitor 3 and firebase 9. The auth import doesn't work anymore.我希望有人可以帮助我如何制作用于 firebase google 登录的旧代码,以便在新的电容器 3 和 firebase 9 中工作。身份验证导入不再起作用。

here's my code in my auth.service.ts:这是我的 auth.service.ts 中的代码:

import {
  Injectable
} from '@angular/core';
import {
  AngularFireAuth
} from '@angular/fire/compat/auth';
import {
  AngularFirestore,
  AngularFirestoreDocument
} from '@angular/fire/compat/firestore';
import '@codetrix-studio/capacitor-google-auth';
import {
  Plugins
} from '@capacitor/core';
import {
  auth
} from 'firebase/app';
import 'firebase/auth';

export class AuthService {
  constructor(private afAuth: AngularFireAuth, private afs:
    AngularFirestore) {}

  async googleSignup() {
    const googleUser = await Plugins.GoogleAuth.signIn(null) as any;
    const credential = auth.GoogleAuthProvider.credential(
      googleUser.authentication.idToken);
    const afUser = await this.afAuth.signInWithCredential(credential);
    return this.updateUserData(
      afUser.user,
      googleUser.givenName,
      googleUser.imageUrl
    );
  }

and here my code for introduction.page.ts where auth.service.ts is called:这里是我的 Introduction.page.ts 代码,其中 auth.service.ts 被调用:

import {
  AuthService
} from '../../services/auth.service';
import {
  Router
} from '@angular/router';

export class IntroductionPage implements OnInit {
  constructor(
    private auth: AuthService,
    private router: Router
  ) {}

  openGoogleSignup() {
    this.auth.googleSignup().then((res) => {
      this.router.navigateByUrl('/app');
    }, err => {
      // Canceled the sign up
    });
  }
}

I've already tried the new import method below for GoogleAuth but I can't follow up with the credentials in my old codes.我已经为 GoogleAuth 尝试了下面的新导入方法,但我无法跟进旧代码中的凭据。 And I get the error "Unhandled Promise rejection: Cannot read properties of undefined (reading 'getAuthInstance')"我收到错误“未处理的承诺拒绝:无法读取未定义的属性(读取'getAuthInstance')”

import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth';

Thank you in taking the time to read this, I'm hoping that someone can guide me to this new methods.感谢您花时间阅读本文,我希望有人可以指导我使用这种新方法。 Goodday everyone.今天是个好日子。

for all who might have a similar problem in the future.对于所有将来可能遇到类似问题的人。 i've managed to find solution thanks to mr.grimm.感谢mr.grimm,我设法找到了解决方案。 the imports should go like this:进口应该是这样的:


    import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth';
    import firebase from 'firebase/compat/app';

and the method to call Google sign in is like this:而调用谷歌登录的方法是这样的:


    async googleSignup() {
        await GoogleAuth.init();
        const googleUser = await GoogleAuth.signIn();
        const credential = firebase.auth.GoogleAuthProvider.credential();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firebase + 电容器离子 Angular:@angular/fire 分析模块不工作 - Firebase + Capacitor Ionic Angular: @angular/fire Analytics Module not working Ionic / Angular / Capacitor / Firebase Facebook 基于身份验证和角色的身份验证 - Ionic / Angular / Capacitor / Firebase Facebook Auth & role based authentification 在离子、电容器、angular 上使用 Firebase 性能监控网络请求 - Monitoring network requests using Firebase performance on ionic, capacitor, angular 离子谷歌地图电容器 - Ionic Google Maps Capacitor 离子/角电容器插件和 firebase FB 身份验证:FacebookLogin 没有 web 实现错误 - Ionic/Angular Capacitor plugin & firebase FB auth : FacebookLogin does not have web implementation error 将 Ionic/Capacitor 应用程序升级到 Angular/FIRe V7 和 Firebase V9 无法在 iOS 上运行 - Upgrade to Angular/FIre V7 and Firebase V9 for Ionic/Capacitor App not working on iOS 在 Ionic 5 中使用 Capacitor 实现 Google Analytics - Implementing Google Analytics in Ionic 5 with Capacitor 由于重定向,Angular 电容器应用程序在 firebase 登录时崩溃 - Angular capacitor app crashes on firebase login due to redirect 离子电容器 Angular 应用程序未显示加载程序 - Ionic Capacitor Angular App is not showing loader Ionic5/角电容装置 API - Ionic5/Angular Capacitor Device API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM