--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/58d5cd56-5e73-4ac4-bef7-866b9a605814%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
currentUser
might also be null because the auth object has not finished initializing. If you use an observer to keep track of the user's sign-in status, you don't need to handle this case. https://firebase.google.com/docs/auth/web/manage-usersHello,I'm not sure why you'd avoid currentUser at all cost? It returns null when not authenticated. It's a nice synchronous way to check the state right now (e.g. when routing to a secured page).Using onAuthStateChanged() is definitely the way to go in the long run. Also, from experience, I'd recommend tying this functionality into your routes. It's much more elegant from my experiences and avoids a lot of needless coupling. Although I'm not a React buff, so I can't walk you through best practices for doing so.☼, Kato
On Wed, Aug 24, 2016 at 12:53 AM, <bkg...@gmail.com> wrote:
I'd like to check if the user is authenticated before loading an authorized page. I'm trying to make use of react-router's onEnter hook and, if unauthenticated, redirect to signin from a ref that's hooked up in the target page component. Otherwise, continue loading the page. I'm not exactly sure how to go about this using firebase.From what I read, Auth.currentUser may return null, so I'm trying to avoid it at all cost. However, previously without firebase, I could check if the user is authenticated by seeing if they have a token in local storage, but firebase seems to encode the key which makes this almost impossible. One way that could work is by setting a custom key-value pair in local storage and listening to Auth.onAuthStateChanged to set it after signin (and remove it after signout), and then checking it in react-router's onEnter hook. But I was wondering if there's a simpler way to do this.Suggestions?
--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/58d5cd56-5e73-4ac4-bef7-866b9a605814%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.