Firebase AUTH won't stay logged in

删除回忆录丶 提交于 2020-06-27 06:11:55

问题


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?


回答1:


Simply 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).



来源:https://stackoverflow.com/questions/37399837/firebase-auth-wont-stay-logged-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!