Google Firebase Auth 在 Netlify 上失败,但在本地服务器上工作

Google Firebase Auth Failed on Netlify, But work on local server

当我将我的站点部署到 netlify 时,我无法正确登录,新 google window 自动打开和关闭,我的站点 Clock

function SignIn() {
const signInWithGoogle = () => {
  const provider = new firebase.auth.GoogleAuthProvider();
  auth.signInWithPopup(provider);
};

return (
  <>
    <button className="sign" onClick={signInWithGoogle}>
      Sign in with Google
    </button>
  </>
);

}

function SignOut() {
return (
  auth.currentUser && (
    <button className="sign" onClick={() => auth.signOut()}>
      Sign Out
    </button>
  )
);

}

Picture

只有我部署到netlify上后web才会出现,本地服务器正常

将您当前的 netlify 域添加到 firebase 控制台

首先执行此 url : https://console.firebase.google.com/u/0/project/your_project_name/authentication/providers

然后转到 Authorised domains 部分并添加 https://kreivc-clock.netlify.app/

永远记得检查身份验证错误并提醒它:

const signIn = () => {
    auth
      .signInWithPopup(provider)
      .catch((error) => alert(error.message));
  };