Я выполняю вход с помощью gmail с помощью API Google на своем веб-сайте, и после входа я сохраняю идентификатор, имя пользователя, адрес электронной почты и URL-адрес изображения в базе данных с помощью вызова Ajax и в ответ показываю модальный режим. Все идет хорошо, но если пользователь закрывает модал без выхода и перезагружает страницу, моя функция onSignin выполняется каждый раз, когда страница обновляется / перезагружается.
<div class="form-group">
<div class="g-signin2" data-onsuccess="onSignIn"></div>
</div>
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
var profile_Id = profile.getId();
var profile_Name = profile.getName();
var profile_Email = profile.getEmail();
var profile_Image = profile.getImageUrl();
//ajax call for saving profile information satrt
$.ajax({
type: 'POST',
url: '../action.php',
data: {Id:profile_Id, Name:profile_Name, Email:profile_Email, Image:profile_Image},
success: function(response) {
console.log("Response: " + response);
$('#username').html("Hi "+profile_Name+"!");
document.getElementById("sign-in").style.visibility = "visible";
$('#RatingModal').modal('show');
}
});
sessionStorage.setItem("Id", profile_Id);
$("#LoginModal").modal('hide');
}