Wie kann ich mit Google One Tap überprüfen, ob ein Nutzer bei seinem Google-Konto angemeldet ist?
P粉736935587
P粉736935587 2024-03-27 19:49:08
0
1
319

Meine Frage ist hier (So überprüfen Sie, ob ein Benutzer mit „Google Sign In“ (OAuth 2.0) angemeldet ist), aber das zugehörige Paket ist veraltet (https://developers.google.com/identity/login/network/people ).

Ich verwende Google One Tap in meinen Projekten. Woher weiß ich, ob ein Nutzer über Google One Tap bei seinem Google-Konto angemeldet ist?

P粉736935587
P粉736935587

Antworte allen(1)
P粉805535434

我询问了 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.
}

使用谷歌一键包:

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。

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!