Currently, I am utilizing the Facebook JavaScript SDK for a login button on my website. The functionality is working correctly, but there are two specific use cases where I seem to be encountering some issues.
- One issue arises when the Facebook cookie is available - despite firing the FB.login() function upon click event, it still redirects from index.php to the event.php page.
- Another problem occurs when a user clicks on the logout button on the site. Initially, it redirects to index.php as expected. However, after loading the index.php page, it redirects again to the event.php page.
Below is an excerpt of the code present in index.php:
<script src="//connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : '375834632488230', // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// Additional initialization code here
FB.Event.subscribe('auth.login', function(response) {
window.location="http://mysite.com/event.php";
});
function doLogin(){
console.log("clicked on fb");
FB.login(function(response) {
if (response.session) {
FB.api('/me?fields=email,location,name,first_name,last_name,picture',
function (response) { });
}
} , {scope:'email'});
}
</script>
<a href="#" id="fblogin" class="signinfacebook" onclick="doLogin()">Sign in with
Facebook</a>