反应:Google的“一键式"回调函数未被调用

问题描述:

<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?提示用户登录,单击继续,然后该函数将永远不会被调用! rr!以上摘录自此处的文档也在此处

Why does handleCredentialResponse not get called at all? The user is prompted to log in, they hit continue and then the function never gets called! Grrr! Above taken from docs here and also here

notification注销

nl {g: "display", h: true}
nl {g: "skipped", l: "issuing_failed"}

您在本地测试吗?如前所述,此处,则需要同时添加 http://localhost http://localhost:port_number 到授权JavaScript来源"框.

are you testing locally? As mentioned here, you need to add both http://localhost and http://localhost:port_number to the Authorized JavaScript origins box.