Firebase 3.0 session persistance

試著忘記壹切 提交于 2019-12-04 05:50:22

It may also be worth mentioning that you need to wait for the auth state to resolve. Per the docs:

The recommended way to get the current user is by setting an observer on the Auth object:

firebase.auth().onAuthStateChanged(function(user) {
  if (user) {
    // User is signed in.
  } else {
    // No user is signed in.
  }
});

Link to the docs here: https://firebase.google.com/docs/auth/web/manage-users

In 3.0, users are currently always persisted until signOut() is called (or the user clears local storage).

Firebase Auth JS SDK now supports sessionOnly persistence. For more on this, check https://firebase.google.com/support/release-notes/js#4.2.0 and https://firebase.google.com/docs/auth/web/auth-state-persistence

You can now specify or switch Auth state persistence before or after sign-in. For your case, you can specify session only persistence as follows: firebase.auth().setPersistence(firebase.auth.Auth.Persistence.SESSION)

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