如何为多页面Web应用程序坚持Firebase简单登录身份验证 [英] How to persist Firebase simple login authentication for a multipage WebApplication

查看:149
本文介绍了如何为多页面Web应用程序坚持Firebase简单登录身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用firebase聊天和firepad实时功能在我的Web应用程序有多个页面,如论坛。

我也开始使用Firebase SimpleLogin。我可以以用户身份登录并获取具有uid,id等信息的auth对象。
$ b $ 1现在,如果用户遍历另一个页面(即a新的url(相同的应用程序)被加载),身份验证是否持续?当然,因为我们通过调用ref.login()来手动进行身份验证,所以当第二个页面被加载时,我们如何知道用户是否已经登录?Firebase会在用户的浏览器或本地存储中存储任何cookie?

2)如果用户通过Firebase进行身份验证,并且现在为我的后端服务器的任何一个新页面的请求,我怎么知道用户通过身份验证。我应该手动处理这个3)Firebase身份验证适用于多页面的Web应用程序,其中的HTML页面和内容是服务于firebase以外的后台服务器。



我也检查了下面的问题。


只要本地存储在浏览器上可用,Firebase简单登录会话将在同一域上的页面刷新之间持续存在。通过新的FirebaseSimpleLogin(ref,function(error,user){...})来重新实现Firebase简单登录客户端,以恢复持久会话(如果有的话)。

使用这种方法,您的回调会自动以用户的登录状态被调用。请注意,您不需要再次调用 .login(...)来获取会话,因为调用 .login(...) 会一直尝试创建一个新的会话。



一旦用户通过认证,就可以开始写< href =https://www.firebase.com/docs/security/security-rules.html =nofollow> Firebase安全规则,利用 auth 变量,对于任何经过身份验证的用户来说都是非空的,并且在使用Firebase简单登录时将包含有用的用户信息(如用户标识符)。请参阅任何简单登录身份验证的身份验证部分。提供商页面以查看确切的有效内容。



如果您已经有一个身份验证系统要与Firebase集成,或者简单登录不足以满足您的需求您可以随时使用您自己的自定义数据生成自定义令牌。这些标记可以包含您选择的任意JSON有效载荷,这些有效载荷将在您的Firebase安全规则中的 auth 变量中可用。



有关详情,请参阅 Firebase安全快速入门


I have been using firebase chat and firepad for real time functionality in My Web Application which has multiple pages like a forum.

I started using the Firebase SimpleLogin too.I am able to login as a user and get the auth object which has the uid,id etc info.

1)Now if the user traverses to another page(i.e a new url(same application) is loaded ),does the authentication persist ? Ofcourse as we are manually doing the authentication by calling ref.login(),how can we know if the user is logged in when the second page is loaded.Will firebase store any cookie in user's browser or local storage ?

2)If the user is authenticated through firebase and now for for any request to my backend server for a new page ,how will I know that the user is authenticated.Should I be manually handling this by inserting some cookie in the browser or a hidden form field once firebase login happens ?

3)Is firebase Authentication suitable for multi page web application where the html pages and content are served from a back server other than firebase.?

I have checked the below question too.

Firebase JWT Authentication, Continually Send Token?

解决方案

As long as browser cookies and local storage are both local storage is available on the browser, Firebase Simple Login sessions will be persisted across page refreshes on the same domain. Simply reinstantiate the Firebase Simple Login client via new FirebaseSimpleLogin(ref, function(error, user) { ... }) to restore a persisted session, if one is available.

Using this approach, your callback will automatically be invoked with the login state of the user. Note that you do not need to call .login(...) again to pick up a session, as calling .login(...) will always try to create a new session.

Once the user is authenticated, you can begin writing Firebase Security Rules, making use of the auth variable, which is non-null for any authenticated user, and will contain useful user information (such as user ids) when using Firebase Simple Login. See the 'After Authenticating' section of any Simple Login auth. provider page to see the exact payload.

In the event that you already have an authentication system you'd like to integrate with Firebase, or Simple Login is not sufficient for your needs, you can always generate Custom Tokens with your own custom data. These tokens can contain any arbitrary JSON payload of your choosing, which will be available in your Firebase security rules under the auth variable.

See the Firebase Security Quickstart for more information.

这篇关于如何为多页面Web应用程序坚持Firebase简单登录身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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