如何为多页面Web应用程序坚持Firebase简单登录身份验证 [英] How to persist Firebase simple login authentication for a multipage WebApplication
问题描述
我一直在使用firebase聊天和firepad实时功能在我的Web应用程序有多个页面,如论坛。
我也开始使用Firebase SimpleLogin。我可以以用户身份登录并获取具有uid,id等信息的auth对象。
$ b $ 1现在,如果用户遍历另一个页面(即a新的url(相同的应用程序)被加载),身份验证是否持续?当然,因为我们通过调用ref.login()来手动进行身份验证,所以当第二个页面被加载时,我们如何知道用户是否已经登录?Firebase会在用户的浏览器或本地存储中存储任何cookie?
我也检查了下面的问题。
只要 使用这种方法,您的回调会自动以用户的登录状态被调用。请注意,您不需要再次调用 一旦用户通过认证,就可以开始写< href =https://www.firebase.com/docs/security/security-rules.html =nofollow> Firebase安全规则,利用 如果您已经有一个身份验证系统要与Firebase集成,或者简单登录不足以满足您的需求您可以随时使用您自己的自定义数据生成自定义令牌。这些标记可以包含您选择的任意JSON有效载荷,这些有效载荷将在您的Firebase安全规则中的 有关详情,请参阅 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 Using this approach, your callback will automatically be invoked with the login state of the user. Note that you do not need to call Once the user is authenticated, you can begin writing Firebase Security Rules, making use of the 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 See the Firebase Security Quickstart for more information. 这篇关于如何为多页面Web应用程序坚持Firebase简单登录身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!新的FirebaseSimpleLogin(ref,function(error,user){...})
来重新实现Firebase简单登录客户端,以恢复持久会话(如果有的话)。
.login(...)
来获取会话,因为调用 .login(...)
会一直尝试创建一个新的会话。
auth
变量,对于任何经过身份验证的用户来说都是非空的,并且在使用Firebase简单登录时将包含有用的用户信息(如用户标识符)。请参阅任何简单登录身份验证的身份验证部分。提供商页面以查看确切的有效内容。
auth
变量中可用。
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. .login(...)
again to pick up a session, as calling .login(...)
will always try to create a new session.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.auth
variable.