Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ionic framework 离子角电容器Firebase:谷歌登录_Ionic Framework_Google Authentication_Capacitor - Fatal编程技术网

Ionic framework 离子角电容器Firebase:谷歌登录

Ionic framework 离子角电容器Firebase:谷歌登录,ionic-framework,google-authentication,capacitor,Ionic Framework,Google Authentication,Capacitor,离子角电容器Firebase应用程序错误 使用@codetrix studio/google auth,建议的代码是: Plugins.GoogleAuth.signIn(); async googleSignIn() { let googleUser = await Plugins.GoogleAuth.signIn(); const credential = auth.GoogleAuthProvider.credential(googleUser.authentication.i

离子角电容器Firebase应用程序错误

使用@codetrix studio/google auth,建议的代码是:

Plugins.GoogleAuth.signIn();

async googleSignIn() {
  let googleUser = await Plugins.GoogleAuth.signIn();
  const credential = auth.GoogleAuthProvider.credential(googleUser.authentication.idToken);
  return this.afAuth.auth.signInAndRetrieveDataWithCredential(credential);
}
错误消息:类型AngularFireAuth上不存在属性“auth” 我可以让它与电子邮件注册一起使用,但不能与谷歌一起使用。谢谢你的建议

这似乎有效:

在auth.service.ts中: 进口

谷歌签名:

    async googleSignIn() {
    const googleUser = await 
    Plugins.GoogleAuth.signIn();
    const credential = firebase.auth.GoogleAuthProvider.credential(googleUser.authentication.idToken);
    return this.afAuth.signInAndRetrieveDataWithCredential(credential);   
 }

您需要导入一些库才能识别它。请确保已为angularfire和firebase安装了所有必需的firebase库

我有这个代码

//first import AngularFireAuth

import {AngularFireAuth} from "@angular/fire/auth"

//then import firebase

import firebase from 'firebase/app';

//define auth variable of AngularFireAuth in constructor

constructor(private auth: AngularFireAuth) {}

async googleSignIn() {

 let googleUser = await Plugins.GoogleAuth.signIn();

  //use imported firebase to get user credential from google

  const credential = firebase.auth.GoogleAuthProvider.credential(googleUser.authentication.idToken);


  //Then use auth variable of AngularFireAuth to sign user using firebase authentication

  return this.auth.signInWithCredential(credential);

  //If you want to get user signed user details you can do this 

   return this.auth.signInWithCredential(credential).then((userCredential: firebase.auth.UserCredential)=>{

   //userCredential object contains all details of the signed user.

   console.log(userCredential)
});


}

您还可以按如下方式导入'auth':从'firebase/app'导入{auth};然后您可以使用:原始代码:const credential=auth.GoogleAuthProvider.credential(googleUser.authentication.idToken);它起作用了!只需将SignAndRetrieveDataWithCredential()更改为signInWithCredential(),因为第一个已弃用。
//first import AngularFireAuth

import {AngularFireAuth} from "@angular/fire/auth"

//then import firebase

import firebase from 'firebase/app';

//define auth variable of AngularFireAuth in constructor

constructor(private auth: AngularFireAuth) {}

async googleSignIn() {

 let googleUser = await Plugins.GoogleAuth.signIn();

  //use imported firebase to get user credential from google

  const credential = firebase.auth.GoogleAuthProvider.credential(googleUser.authentication.idToken);


  //Then use auth variable of AngularFireAuth to sign user using firebase authentication

  return this.auth.signInWithCredential(credential);

  //If you want to get user signed user details you can do this 

   return this.auth.signInWithCredential(credential).then((userCredential: firebase.auth.UserCredential)=>{

   //userCredential object contains all details of the signed user.

   console.log(userCredential)
});


}