Firebase: Google OAuth Infinite Redirects

吃可爱长大的小学妹 提交于 2019-12-04 19:33:35

Any time you call ref.authWithOAuthRedirect(...), you're telling Firebase to initiate the redirect-based authentication flow and redirect the browser to the OAuth provider. Calling this method will always attempt to create a new session, even if one is already persisted in the browser.

To only attempt creation of a new login session if one doesn't already exist, try the following which makes use of the onAuth(...) event listener:

var ref = new Firebase("https://<firebase url>.firebaseio.com");
ref.onAuth(function(authData) {
  if (authData !== null) {
    console.log("Authenticated successfully with payload:", authData);
  } else {
    // Try to authenticate with Google via OAuth redirection
    ref.authWithOAuthRedirect("google", function(error, authData) {
      if (error) {
        console.log("Login Failed!", error);
      }
    });
  }
})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!