How to persist Firebase simple login authentication for a multipage WebApplication

后端 未结 1 530
时光说笑
时光说笑 2021-02-03 14:32

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 SimpleL

1条回答
  •  时光说笑
    2021-02-03 15:06

    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.

    0 讨论(0)
提交回复
热议问题