admin管理员组文章数量:1391943
When I log into a firebase app using signInWithEmailAndPassword(email, password)
, the user is logged in. Then, if I reload the page, the user is no longer logged in. If I go to another webpage with the same firebase apiKey and everything, the user still isn't logged in. How would I go about making sure the user stays logged in until firebase.auth().signOut()
is called?
When I log into a firebase app using signInWithEmailAndPassword(email, password)
, the user is logged in. Then, if I reload the page, the user is no longer logged in. If I go to another webpage with the same firebase apiKey and everything, the user still isn't logged in. How would I go about making sure the user stays logged in until firebase.auth().signOut()
is called?
- A quick guess is that you're not monitoring authentication state (see the docs for that). If that's not it, please share the minimal, plete code that allows us to reproduce your problem. – Frank van Puffelen Commented May 23, 2016 at 20:37
-
@FrankvanPuffelen Turns out I was just trying to get
firebase.auth().currentUser
without the state change monitor. I took your advice and it works now. Thanks! – hyperneutrino Commented May 23, 2016 at 20:41 - Also, to whomever close-voted it, how is it off-topic? Please elaborate. – hyperneutrino Commented May 23, 2016 at 20:43
- It works after my small ment. I didn't feel it worth an answer (since I'm pretty sure I've pointed the same out in the past few days), so voted to close as it is unlikely others will find this one. – Frank van Puffelen Commented May 23, 2016 at 20:56
- @FrankvanPuffelen Okay, should I delete it then? – hyperneutrino Commented May 24, 2016 at 12:59
1 Answer
Reset to default 8Simply using firebase.auth().currentUser
usually won't work because when that's loaded, Firebase usually hasn't authenticated and connected a user account yet. Instead, wait for the authorization state to change using firebase.auth().onAuthStateChanged(func)
where func
is called when the auth state is changed (which could mean signing in or signing out or switching accounts).
本文标签: javascriptFirebase AUTH won39t stay logged inStack Overflow
版权声明:本文标题:javascript - Firebase AUTH won't stay logged in - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744735056a2622276.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论