[英]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.