React:未调用 Google“One Tap”回调函数

IT技术 reactjs google-oauth
2021-04-28 14:10:35
<script src="https://accounts.google.com/gsi/client"></script>
...
declare var google: any;
...

  useEffect(() => {
    const handleCredentialResponse = (response: any) => {
      console.log(response);
    };
    const client_id = process.env.REACT_APP_GOOGLE_CLIENT_ID;
    const callback = handleCredentialResponse;
    const auto_select = true;
    google.accounts.id.initialize({ client_id, callback, auto_select });
    google.accounts.id.prompt((notification: any) => {
      console.log(notification);
    });
  }, []);

为什么根本handleCredentialResponse没有被调用?用户被提示登录,他们点击继续,然后该函数永远不会被调用!呸!以上取自此处此处的文档

notification注销

nl {g: "display", h: true}
nl {g: "skipped", l: "issuing_failed"}
1个回答

你是在本地测试吗?如前所述在这里,你需要添加两个HTTP://本地主机HTTP://本地主机:端口号到授权的JavaScript源框。