JavaScript: Prevent GooglePlus automatic sign-in and get user information

/* <!-- This is the required metatag that you need to fill in with your client ID --> <!-- <meta name="google-signin-client_id" content="YOUR_CLIENT_ID.apps.googleusercontent.com"> <!-- This is where the Login Button will be rendered --> <!-- <div id="my-signin2"></div> --> */ window.onGoogleSuccess = function (googleUser) { var profile = googleUser.getBasicProfile(); if (!profile) return false; // Store information on variables var name = profile.getName(), email = profile.getEmail(); // Use the data declared above, like making an ajax request // Load Google Auth2 lib, and log the user out gapi.load('auth2', function() { var auth2 = gapi.auth2.getAuthInstance(); auth2.signOut(); console.log('Logged out.'); }); }; window.onGoogleFailure = function (error) { console.log(error); }; // This method is called by Google JSONP window.googleRenderButton = function () { gapi.signin2.render('my-signin2', { 'scope': 'https://www.googleapis.com/auth/plus.login', 'width': 255, 'height': 40, 'longtitle': true, 'theme': 'dark', 'onsuccess': onGoogleSuccess, 'onfailure': onGoogleFailure }); }; // <!-- Include Google API that calls googleRenderButton onLoad --> // <!-- <script src="https://apis.google.com/js/platform.js?onload=googleRenderButton" async defer></script> -->
If you are building a login system that implements steps such as Facebook, Google+ and Manual Registration you will probably face some issues regarding Google+ auto-login "feature".

Once you make use the login feature, you are seen in "Signed in" state, and for a system like this you would need to have a "Logout" button to be able to change to another registration method.

This happens because Google+ always fires callback (as the user is signed in), and you are not able to see if the login

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.