How to check if user is logged in or not with “Google Sign In” (OAuth 2.0)

前端 未结 4 1054
[愿得一人]
[愿得一人] 2020-12-15 22:25

I am implementing Google log in for the first time as described here and here.

I am using HTML with Javascript.

The problem that needs solving is as follows:

4条回答
  •  被撕碎了的回忆
    2020-12-15 22:50

    Adding on to Joseph's answer above, you can then get information about the user by calling auth2.currentUser.get().getBasicProfile().

        if (auth2.isSignedIn.get()) {
            googleUserProfile = auth2.currentUser.get().getBasicProfile()
            console.log('ID: ' + googleUserProfile.getId());
            console.log('Full Name: ' + googleUserProfile.getName());
            console.log('Given Name: ' + googleUserProfile.getGivenName());
            console.log('Family Name: ' + googleUserProfile.getFamilyName());
            console.log('Image URL: ' + googleUserProfile.getImageUrl());
            console.log('Email: ' + googleUserProfile.getEmail());
        }
    

    From the docs: https://developers.google.com/identity/sign-in/web/people

提交回复
热议问题