Node.JS Firebase Auth-是否可以像保持客户端Firebase Auth一样保持用户会话? [英] Node.JS Firebase Auth - Is there a way to keep a user session like with client side Firebase Auth?

查看:80
本文介绍了Node.JS Firebase Auth-是否可以像保持客户端Firebase Auth一样保持用户会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Node.JS,并且正在尝试将Firebase Auth引入我的应用程序.使用客户端Firebase身份验证,您可以只执行 firebase.auth().currentUser ,但在节点中,因为脚本不是在客户端上运行,而是在服务器上运行,所以您不能使用 firebase.auth().currentUser .是否有一种涉及会话或cookie(我认为)的方法来获取用户数据并从节点使用常规Firebase Auth操作,就像客户端Firebase Auth一样?

I am learning Node.JS and I am trying to bring Firebase Auth into my application. With client-side firebase auth, you can just do firebase.auth().currentUser but in node, as the script is not run on the client, but once on the server, you cannot use firebase.auth().currentUser. Is there a way involving sessions or cookies (I think) to get user data and use normal Firebase Auth operations from node just like client side Firebase Auth?

(我正在将Express与Node一起使用)

(I am using express with Node)

推荐答案

您已经发现,当前用户对于发送到节点脚本的请求没有任何概念.

As you've found there is no concept of a current user for a request sent to a node script.

您要做的是在客户端上使用Firebase身份验证,然后发送生成ID令牌到您的node.js脚本,在该脚本中,您

What you'll want to do is use Firebase Authentication on the client, and then send the resulting ID token to your node.js script, where you verify that the token is valid using the Firebase Admin SDK.

这篇关于Node.JS Firebase Auth-是否可以像保持客户端Firebase Auth一样保持用户会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆