Stay organized with collections
Save and categorize content based on your preferences.
After the Google Sign-In client has been initialized, you can attach
handlers that check various attributes and methods of the client to determine
the user's session state. You can use information returned by the client object
to help sync your site's user experience across multiple tabs and devices for
your user.
The following code demonstrates using the 2.0 client method
attachClickHandler to create a callback that either silently finishes sign-in
for the user, or prompts the user to re-authorize based on the state of the
user's session.
/***TheSign-Inclientobject.*/varauth2;/***InitializestheSign-Inclient.*/varinitClient=function(){gapi.load('auth2',function(){/***RetrievethesingletonfortheGoogleAuthlibraryandsetupthe*client.*/auth2=gapi.auth2.init({client_id:'CLIENT_ID.apps.googleusercontent.com'});//Attachtheclickhandlertothesign-inbuttonauth2.attachClickHandler('signin-button',{},onSuccess,onFailure);});};/***Handlesuccessfulsign-ins.*/varonSuccess=function(user){console.log('Signed in as '+user.getBasicProfile().getName());};/***Handlesign-infailures.*/varonFailure=function(error){console.log(error);};
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-10-31 UTC."],[[["The Google Sign-In JavaScript library is deprecated and will eventually be sunset; developers should consult the Deprecation and Sunset guide for migration details and timelines."],["Google Sign-In will require the use of FedCM APIs in the future, so developers should conduct an impact assessment to ensure their sign-in functionality remains unaffected."],["This page provides code demonstrating how to initialize the Google Sign-In client and attach click handlers to manage user sign-in and session state."],["Developers can utilize the `auth2` object to handle successful and failed sign-in attempts, accessing user information upon successful authentication."]]],[]]