Can anyone assist me with the final step of my Facebook login feature?
The current issue is that when a new user first signs in, they are greeted with a popup labeled 'www.facebook.com/v11.0/dialog/oauth' that asks them to authorize my page to access their information.
The problem arises when the user accepts the terms and clicks on 'continue as name' button, instead of being directed to my homepage as intended, they remain on the login page. They then have to click on the 'Connect by Facebook' button again, which finally redirects them to the correct page.
Basically, I am seeking a solution to streamline the process by prompting the redirect within the oauth popup and avoiding the need for a second click.
My JavaScript code is set up like this:
$(document).ready(function(){
$('.login-main').on("click", ".facebook_login_class", function(){
console.log('FACEBOOK LOGIN OPTION SELECTED');
FB.getLoginStatus(function(res){
if(res.status == "connected" ){
console.log('Connected on Facebook');
FB.api('/me?fields=email,name,first_name,last_name', function(fbUser) {
$.ajax({
url:'facebook_login_ajax/',
method:'GET',
data:{
email:fbUser.email,
code:fbUser.id,
},
success:function(response){
if (response.Success == true){
window.location.href = '/myhomepage/';
}
}
});
});
}else{
console.log('NOT CONNECTED!');
FB.login();
}
FB.getLoginStatus(function(response) {
});
});
});
});
I believe the issue lies within the FB.login(); section of my code, as that is where new users are taken before providing authorization. My JavaScript skills are still improving, so it feels like I may be overlooking something simple.
Do any of you have a suggestion for resolving this issue?
Thank you very much