首頁  >  問答  >  主體

如何驗證使用者是否使用 Google One Tap 登入其 Google 帳戶?

我的問題在這裡(如何檢查用戶是否使用“Google Sign In”(OAuth 2.0)登入),但相關軟體包已被棄用(https://developers.google.com/identity/登入/網絡/人員)。

我在我的專案中使用 Google One Tap。我如何知道用戶是否已使用 Google One Tap 登入其 Google 帳戶。

P粉736935587P粉736935587205 天前334

全部回覆(1)我來回復

  • P粉805535434

    P粉8055354342024-03-28 11:00:03

    我問了 Google Bard,我認為它給了很好的答案。

    有幾種方法可以檢查使用者是否登入 Google。

    • 檢查使用者的會話儲存。 如果使用者已登錄,使用者的會話儲存將包含使用者的 Google ID 金鑰。您可以檢查此密鑰以了解使用者是否已登入。 < /里>
    • 使用 Google Sign In API。 Google Sign In API 提供了一種檢查使用者是否登入的方法。您可以使用此 API 取得使用者的 Google ID 以及有關其身分的其他資訊帳戶。
    • 檢查使用者的瀏覽器 Cookie。 如果使用者已登錄,使用者的瀏覽器 Cookie 將包含用於 Google 登入服務的 Cookie。您可以檢查此 Cookie 以了解使用者是否已登入。

    以下是如何檢查使用者是否使用 Google Sign In API 登入的範例:

    const googleSignIn = require('google-signin');
    
    const auth2 = googleSignIn.build();
    
    const isSignedIn = await auth2.isSignedIn();
    
    if (isSignedIn) {
      // The user is logged in.
      const user = await auth2.currentUser();
    
      // Do something with the user's information.
    } else {
      // The user is not logged in.
    }

    使用Google一鍵套件:

    const googleOneTap = require('google-one-tap');
    
    const auth2 = googleOneTap.build();
    
    const isSignedIn = await auth2.isSignedIn();
    
    if (isSignedIn) {
      // The user is logged in.
      const user = await auth2.currentUser();
    
      // Do something with the user's information.
    } else {
      // The user is not logged in.
    }

    此外,還可以透過這兩個套件來存取使用者的其他資訊。如果您需要不同的解決方案,可以使用 Google Bard。

    回覆
    0
  • 取消回覆