Google sign-in : Disable automatic authentication

Viewed 786

Can we disable automatic authentication when user are not connected?

In other words I would like the user to connect only when he click on the button.

Here is my code :

<script src="https://apis.google.com/js/platform.js?onload=onLoadGoogle" async defer></script>
                    <script>

                        function onLoadGoogle() {
                            gapi.load('auth2', function () {
                                gapi.auth2.init();
                            });
                        }

                        function onSignIn(googleUser) {
                            var profile = googleUser.getBasicProfile();

                            // The ID token you need to pass to your backend:
                            var id_token = googleUser.getAuthResponse().id_token;

                            if (gapi.auth2.getAuthInstance().isSignedIn.get()) {
                                $.ajax({
                                    type: 'POST',
                                    url: $('#yBaseUrl').val() + '/ControllerAuthentification/getMailAllCompte',
                                    data: {
                                        mail: profile.getEmail()
                                    },
                                    dataType: "json",
                                    success: function (data) {
                                        if (data == 1) {
                                            window.location.href = "index.php/ControllerAccueil";

                                        },
                                    error: function (e) {
                                        if (e.responseText == "") {
                                            toastr.info("Vous n'ĂȘtes pas inscrit par ce compte google!!", 'Notification');
                                        }
                                        console.log(e.responseText);

                                    }
                                });
                            }
                        }
                        ;
                    </script>

The problem here is that in the function onSignIn the connection is already made and therefore always

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

returns true

1 Answers
Related