1

I'm trying to make a part of my website that is restricted to only that of people who are logged in.

Currently, I am able to check their login status with: firebase.auth().onAuthStateChanged(function (user)

But I was wondering whether this was the correct option to use, as it displays the restricted page for one or two seconds before the user gets redirected to the homepage.

Are there any alternatives that provide a better solution?

Thanks in advance.

  • please check the below link https://stackoverflow.com/questions/37873608/how-do-i-detect-if-a-user-is-already-logged-in-firebase – Arun Prasat Jun 26 '19 at 11:12
  • I assume you are creating a SPA. Do you use any specific framework? =) – Benjamin Beganović Jun 26 '19 at 15:28
  • No, I don't use any frameworks at the moment. I'm kind of creating a SPA for the restricted area but the frontpage and the restricted area are separate. –  Jun 26 '19 at 15:41

2 Answers2

0

access firebase.auth().currentUser

Medet Tleukabiluly
  • 11,662
  • 3
  • 34
  • 69
  • Sorry, I don't you quite get what I'm asking - I want to know if there is a better method that does not require having to wait for the script to check a users authentication, as at the moment there is a 1-2 second delay before a user gets redirected back to the homepage. –  Jun 26 '19 at 11:03
0

What you are doing now with the auth state change listener is the documented, recommended approach. You should expect that there could be some time before the sign in state is fully available to your page. If you're finding that it takes longer than you'd like, perhaps you could change your app's UI to better handle this case.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441