Currently, I am working on integrating Google login into my web application using AngularJS. Whenever the popup opens up for logging into my Google account or selecting an existing account, I encounter an issue where the popup closes with an error message in the console (popup_closed_by_user).
This problem occurs consistently every time I attempt it. I have tested it on both Chrome and Edge browsers, with the same outcome. Clearing cookies and cache did not resolve the issue. Additionally, the Google+ API and OAuth are enabled, and the origin URL is correctly added to the configuration.
.directive('googleSignInButton',function(){
return {
scope:{
gClientId:'@',
callback: '&onSignIn'
},
template: '<button class="button button-block button-positive" ng-click="onSignInButtonClick()">Sign in with Google</button>',
controller: ['$scope','$attrs',function($scope, $attrs){
gapi.load('auth2', function() {
//load in the auth2 api's, without it gapi.auth2 will be undefined
gapi.auth2.init(
{
client_id: $attrs.gClientId
}
);
var GoogleAuth = gapi.auth2.getAuthInstance();//get's a GoogleAuth instance with your client-id, needs to be called after gapi.auth2.init
$scope.onSignInButtonClick=function(){//add a function to the controller so ng-click can bind to it
GoogleAuth.signIn().then(function(response){//request to sign in
$scope.callback({response:response});
});
};
});
}]
};
});