Welcome Guest, Not a member yet? Register   Sign In
Auto relaod after login
#1

I have a google login on my website, with an auto reload after the user is correctly logged in.
The problem is every time the user is browsing the website it is reloading the page.
So if he opens an article, it will load the page and the reload the page.
Here is my JS
Code:
 
  function onSuccess(googleUser) {
    var static_url = 'https://www.mywebsite.com/';
   
    gapi.client.load('oauth2', 'v2', function () {
        var request = gapi.client.oauth2.userinfo.get({
            'userId': 'me'
        });
        request.execute(function (resp) {
onclick="signOut();">Sign out</a></h3>';
</b>'+resp.id+'</p><p><b>Name: </b>'+resp.name+'</p><p><b>Email: </b>'+resp.email+'</p><p><b>Gender: </b>'+resp.gender+'</p><p><b>Locale: </b>'+resp.locale+'</p><p><b>Google Profile:</b> <a target="_blank" href="'+resp.link+'">click to view profile</a></p>';
           
           
            $.ajax({
                type: 'POST',
                url: static_url+'/deals/google_login',
                async: false,
                data: {email:resp.email,name:resp.name},
                success: function (result) {
                    $('.msg').removeClass('alert alert alert-danger');
                    $('.lmsg').show();
                    if(result == 'blocked'){
                        signOut();
                        $('.lmsg').addClass('alert alert-danger');
                        $('.lmsg').html('Your account is blocked');
                        setTimeout(function() {
                            $('.lmsg').fadeOut('slow');
                        }, 3000);
                    }else{
                       
                        if( window.localStorage ){
                        if( !localStorage.getItem('firstLoad') ){
                            $('.lmsg').addClass('alert');
                            $('.lmsg').html('Successfully Logged In');
                            localStorage['firstLoad'] = true;
                            $('.lmsg').fadeOut('slow');
                            window.location.reload();
                        }else
                            localStorage.removeItem('firstLoad');
                        }

                    }
                }
            });           
        });
    });
}
If I remove the window.location.reload(); the issue is gone, but user get stuck on the login page, so I really need to reload the page after the user logged in. To redirect it to the front page and load his profile picture, name...

Does any one already face this issue? or have a solution?

Thank you
Reply
#2

I didn't look properly at gapi but I thought this was a decent tutorial.

https://code.tutsplus.com/tutorials/crea...-cms-33214

For the record I've only ever used single sign ons in React
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply




Theme © iAndrew 2016 - Forum software by © MyBB