简体   繁体   English

使用 firebase 用谷歌登录

[英]Sign in with google using firebase

I am working on a react app that lets a user sign in with user.我正在开发一个允许用户使用用户登录的反应应用程序。 I am using Firebase to handle authentication.我正在使用 Firebase 来处理身份验证。 I am using express to write cloud functions.我正在使用 express 编写云函数。 I want to set up signing in with Google but I have a couple of questions.我想设置使用 Google 登录,但我有几个问题。

Here is what I have so far on the backend of the route to sign in with Google:到目前为止,我在使用 Google 登录的路线的后端拥有以下内容:

const { id_token } = req.body //de-structure id token passed in through body of request

const credential = firebase.auth.GoogleAuthProvider.credential(id_token); 

How do I register this user using these credentials into my database?如何使用这些凭据将此用户注册到我的数据库中? How do I check if this user is already registered?如何检查此用户是否已注册? I want to be able to save data for this user so every time he/she logs in with google, his/her data is saved.我希望能够为该用户保存数据,因此每次他/她使用 google 登录时,都会保存他/她的数据。

You should import firebase admin in your application.您应该在您的应用程序中导入 firebase admin 。

Admin SDK allows to interact with firebase from the privileged environment to perform actions like:管理员 SDK 允许从特权环境与 firebase 交互以执行以下操作:

  1. Read and write Realtime Database data with full admin privileges以完全管理员权限读取和写入实时数据库数据
  2. Generate and verify firebase based auth tokens生成并验证基于 firebase 的身份验证令牌
  3. Access Google Cloud Platform resources like Cloud Storage buckets and Cloud Firestore databases associated with your Firebase projects访问与您的 Firebase 项目关联的 Google Cloud Platform 资源,例如 Cloud Storage 存储分区和 Cloud Firestore 数据库

I hope this helps.我希望这有帮助。

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

相关问题 使用firebase云函数登录 - Sign In using firebase cloud functions Selenium 自动化 firebase google 登录过程 - Selenium automate firebase google sign in process 使用node.js使用Firebase-Admin登录 - Sign in with Firebase-Admin using node.js 谷歌云/firebase 存储错误:没有 `client_email` 无法签署数据。 ...名称:'SigningError' - Google cloud/firebase storage Error: Cannot sign data without `client_email`. ... name: 'SigningError' 如何从服务器端通过Google登录创建Firebase用户 - How to create a Firebase user with Google Sign-in from server-side 使用AWS Amplify验证Google登录 - federatedSignin返回null? - Using AWS Amplify to authenticate Google Sign In - federatedSignin returns null? 使用Google Cloud Key Management Service签署JSON Web令牌 - Using Google Cloud Key Management Service to sign JSON Web Tokens 使用带有 Node.js 后端的 Angular 应用程序进行 Google 登录 - Google Sign-in using Angular app with a Node.js backend Google Firebase - 使用 Firebase 数据动态更新文本区域 - Google Firebase - Dynamically update text area using firebase data 使用Google登录Firebase时,电子邮件为空 - Email was null when using Google login Firebase
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM