React:Google“一键”回调函数未被调用

Bil*_*ill 5 google-oauth reactjs

<script src="https://accounts.google.com/gsi/client"></script>\n...\ndeclare var google: any;\n...\n\n  useEffect(() => {\n    const handleCredentialResponse = (response: any) => {\n      console.log(response);\n    };\n    const client_id = process.env.REACT_APP_GOOGLE_CLIENT_ID;\n    const callback = handleCredentialResponse;\n    const auto_select = true;\n    google.accounts.id.initialize({ client_id, callback, auto_select });\n    google.accounts.id.prompt((notification: any) => {\n      console.log(notification);\n    });\n  }, []);\n
Run Code Online (Sandbox Code Playgroud)\n\n

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

\n\n

注销notification

\n\n
nl\xc2\xa0{g: "display", h: true}\nnl\xc2\xa0{g: "skipped", l: "issuing_failed"}\n
Run Code Online (Sandbox Code Playgroud)\n

Gui*_*bin 2

你在本地测试吗?如此处所述,您需要将http://localhosthttp://localhost:port_number添加到“授权 JavaScript 来源”框中。