简体   繁体   English

用户已经登录后,如何避免Google登录弹出?

[英]How to avoid the google Sign In Pop up when the user is already logged in?

I am using the below code to make a user sign in through google. 我正在使用以下代码使用户通过google登录。

    <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet" type="text/css">
  <script src="https://apis.google.com/js/api:client.js"></script>
  <script>
      var googleUser = {};
      var startApp = function () {
          gapi.load('auth2', function () {
              // Retrieve the singleton for the GoogleAuth library and set up the client.
              auth2 = gapi.auth2.init({
                  client_id: [my client id],
                  cookiepolicy: 'single_host_origin',
                  // Request scopes in addition to 'profile' and 'email'
                  scope: 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/plus.me'
              });
          });
      };

      function checkUser() {
          if (auth2.isSignedIn.get()) {
              onSignIn(auth2.currentUser.po.po);
          }
          else {
              gapi.auth.authorize({ client_id: [my client id], scope: 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/plus.me', immediate: false }, onSignIn);
          }
      }

      function onSignIn(googleUser) {
          alert('Access Token' + googleUser.access_token);
          //location.href = "ServerSide.aspx?acccessToken=" + googleUser.access_token;
      }
  </script>
  <style type="text/css">
    #customBtn {
      display: inline-block;
      background: #4285f4;
      color: white;
      width: 190px;
      border-radius: 5px;
      white-space: nowrap;
    }
    #customBtn:hover {
      cursor: pointer;
    }
    span.label {
      font-weight: bold;
    }
    span.icon {
      /*background: url('/identity/sign-in/g-normal.png') transparent 5px 50% no-repeat;*/
      display: inline-block;
      vertical-align: middle;
      width: 42px;
      height: 42px;
      border-right: #2265d4 1px solid;
    }
    span.buttonText {
      display: inline-block;
      vertical-align: middle;
      padding-left: 42px;
      padding-right: 42px;
      font-size: 14px;
      font-weight: bold;
      /* Use the Roboto font that is loaded in the <head> */
      font-family: 'Roboto', sans-serif;
    }
  </style>
  <!-- In the callback, you would hide the gSignInWrapper element on a
  successful sign in -->
  <div id="gSignInWrapper" onclick="checkUser()">
    <span class="label">Sign in with:</span>
    <div id="customBtn" class="customGPlusSignIn">
      <span class="icon"></span>`enter code here`
      <span class="buttonText">Google</span>
    </div>
  </div>
  <div id="name"></div>
  <script>startApp();</script>

With this code if the user is even logged in to google the pop comes and go which looks weird.So i want if the user is logged in to google popup should not come and directly makes the user enter the system. 有了这个代码,如果用户甚至登录到Google,弹出的声音看起来就很奇怪。所以我想如果用户登录到Google弹出窗口不应该直接进入系统。 For this i have used "auth2.isSignedIn.get()" on button click but this function always gives me false even if the user is logged in to the google. 为此,我在按钮单击时使用了“ auth2.isSignedIn.get()”,但是即使用户登录到Google,此功能也总是给我错误。 I am stuck at this point.Please if you have any way to achieve this do tell me. 我被困在这一点。如果您有任何办法实现这一目标,请告诉我。

isSignedIn method is available on google auth instance GoogleAuth.isSignedIn.get() , you should use below 在Google身份验证实例GoogleAuth.isSignedIn.get()上可以使用isSignedIn方法,请在下面使用

gapi.auth2.getAuthInstance().isSignedIn.get() gapi.auth2.getAuthInstance()。isSignedIn.get()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google登录:如果用户已经使用侦听器登录,如何避免弹出对话框? - Google Sign-in: how to avoid popup dialog if user is already signed in by using listeners? 如果用户未登录,如何生成弹出窗口? - How to generate a pop-up window if a user is not logged in? 打开新页面时保持用户登录状态:Google登录 - Keep user logged in when opening new page: google sign in 如何使用“Google 登录”检查用户是否登录(OAuth 2.0) - How to check if user is logged in or not with "Google Sign In" (OAuth 2.0) 用户登录后如何显示弹出消息? - How can I show a pop-up message after an user is logged in? 如果用户未登录,则单击单击事件以弹出登录表单 - Catch click event to pop-up login form if user is not logged in 当用户试图离开当前页面时,如何显示弹出窗口? - How to display a pop up, when a user tries to leave the current page? 如何在用户登录时显示 Odoo 教程 - How to show Odoo tutorial pop up when user loggins Firebase身份验证 - 用户在Firebase注册和重定向后未登录 - Firebase Auth - User not logged in after Firebase sign up and redirect 如何使用Firebase Google登录获取登录用户的属性? - How do I get properties of a logged in user using Firebase Google sign-in?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM