I am working with the Facebook API, more specifically with the web SDK.
I have created a login button in the index.html that when you click on it, redirects you to Facebook and in case you log in, you are redirected to the main page.
Here my question, how can I check the status of the user's connection from that home page, so that if the user is not connected the page will redirect him to the index again?
I've been searching the Facebook documentation and none of the solutions seems to work for me.
UPDATE: Doubt solved, the code that I have used finally has been the following:
window.fbAsyncInit = function() {
FB.init({
appId : *AppID*,
xfbml : true,
cookie : true,
version : 'v2.8'
});
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
var uid = response.authResponse.userID;
} else if (response.status === 'not_authorized') {
window.location.replace("http://localhost:8090/index.html");
} else {
window.location.replace("http://localhost:8090/index.html");
}
});
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id))
return;
js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));