使用 Google One Tap 时“suppressed_by_user”是什么意思?

IT技术 javascript reactjs google-authentication
2021-05-16 07:38:13

我试图在用户时钟登录时让一键出现,下面的代码在页面加载后立即运行时工作正常,但如果我尝试让它在点击时运行,那么我会收到错误suppressed_by_user错误没有运行广告拦截插件,我不知道这suppressed_by_user意味着什么?

这里的文档详细说明了错误,但没有解释导致它的原因或如何修复它。

<script src="https://accounts.google.com/gsi/client"></script>
... 
  const signin = () => {
    const handleCredentialResponse = (response: any) => {
      const credential = response.credential;
      const getDetails = async () => {
        const params = new window.URLSearchParams({ credential });
        const url = `${process.env.REACT_APP_API_BASE_URL}/google?${params}`;
        const response = await fetch(url, { method: "GET" });
        const data = await response.json();
        setLoggedIn(true);
        setState({ ...state, participant: data.participant });
      };
      getDetails();
    };
    if (state && state.participant && state.participant.id) {
      setLoggedIn(true);
    } else {
      const client_id = process.env.REACT_APP_GOOGLE_CLIENT_ID;
      const callback = handleCredentialResponse;
      const auto_select = false;
      const cancel_on_tap_outside = false;
      google.accounts.id.initialize({ client_id, callback, auto_select, cancel_on_tap_outside });
      google.accounts.id.prompt((notification: any) => {
        console.log(notification); // rl {g: "display", h: false, j: "suppressed_by_user"}
        console.log(notification.getNotDisplayedReason()); // suppressed_by_user
      });
    }
  };
...
<div className="center--main-join" onClick={signin}>Sign in or Join</div>
1个回答

这意味着用户之前手动关闭了 One Tap 提示,这触发了 Cool Down 功能(如文档所述:https : //developers.google.com/identity/one-tap/web/guides/features#exponential_cooldown)。

在冷却期间,一键提示被抑制。