完全自定义Google SSO按钮

发布于 2025-02-12 21:21:19 字数 1069 浏览 2 评论 0原文

我写了流动的代码给Google SSO的身份用户, 但是,当我使用Google API时,它将他们的iframe推向我的代码,并破坏我的项目的样式! 有人知道一种方法来定义一个单独的按钮,例如下面的代码,当单击它时,Google SSO auth页面将为用户打开?

const googleSSO = (e: { preventDefault: () => void }) => {
    e.preventDefault();
    console.log(google);
    // google.accounts.id.renderButton(document.getElementById('singInDiv'), {
    //   theme: 'outline',
    //   size: 'large',
    //   type: 'icon'
    // });
    return google.accounts.id.initialize({
      client_id:
        'myclientID.apps.googleusercontent.com',
      callback: handleCallbackResponse
    });
  };
 
  return (
    <>
      <IconButton sx={{ ml: 1, mb: 0.5 }} onClick={googleSSO} color="primary">
        <GoogleIcon />
      </IconButton>
      <IconButton sx={{ ml: 1, mb: 0.5 }} onClick={googleSSO} color="primary">
        <GitHubIcon />
      </IconButton>
      <IconButton sx={{ ml: 1, mb: 0.5 }} onClick={googleSSO} color="primary">
        <FacebookIcon />
      </IconButton>
    </>
  );

i wrote flowing code to auth user by google sso,
but when i used google api, it push their iframe in my code and spoils the style of my project!!
Does anyone know a way to define a separate button like the code below and when it is clicked, the google sso auth page will open for the user?

const googleSSO = (e: { preventDefault: () => void }) => {
    e.preventDefault();
    console.log(google);
    // google.accounts.id.renderButton(document.getElementById('singInDiv'), {
    //   theme: 'outline',
    //   size: 'large',
    //   type: 'icon'
    // });
    return google.accounts.id.initialize({
      client_id:
        'myclientID.apps.googleusercontent.com',
      callback: handleCallbackResponse
    });
  };
 
  return (
    <>
      <IconButton sx={{ ml: 1, mb: 0.5 }} onClick={googleSSO} color="primary">
        <GoogleIcon />
      </IconButton>
      <IconButton sx={{ ml: 1, mb: 0.5 }} onClick={googleSSO} color="primary">
        <GitHubIcon />
      </IconButton>
      <IconButton sx={{ ml: 1, mb: 0.5 }} onClick={googleSSO} color="primary">
        <FacebookIcon />
      </IconButton>
    </>
  );

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文