How to refresh expired google sign-in logins?

前端 未结 5 2248
借酒劲吻你
借酒劲吻你 2020-12-07 22:51

I\'m using Google Sign-In. A user comes to my site and logs in with gapi.auth2.getAuthInstance().signIn(), or they are already logged in and when the page loads

5条回答
  •  遥遥无期
    2020-12-07 23:27

    You can accomplish this with listeners.

    var auth2 = gapi.auth2.getAuthInstance();
    
    // Listen for changes to current user.
    // (called shortly before expiration)
    auth2.currentUser.listen(function(user){
    
        // use new user in your OpenID Connect flow
    
    });
    

    This will allow you to keep current credentials, as long as the browser remains active.

    If the computer is put to sleep additional work must done to get current credentials.

    if (auth2.isSignedIn.get() == true) {
        auth2.signIn();
    }
    

提交回复
热议问题