Facebook sometimes doesn't pass signed request

726 Views Asked by At

I have a Facebook Pagetab application I've developed using Node JS and Express. It seems to work perfectly most of the time, but sometimes it doesn't. I'm having issues replicating the issue, which therefore makes it difficult to debug, but I think I've located the problem.

When the home page loads I utilise Thuzi's Facebook module (https://github.com/Thuzi/facebook-node-sdk) to screen the signed request that Facebook passes me, in order to determine if the user likes the page or not:

var fb = require('fb');
var signedRequest  = fb.parseSignedRequest(req.body.signed_request, process.env.FACEBOOK_APP_SECRET);   

if(signedRequest ){
    if( signedRequest.page.liked){
        res.redirect('/authorise');                         
    }
    else {
        res.redirect('/gate');
    }
}
else {
    console.log('No signed request');
}   

However, sometimes the 'No signed request' is being sent to the console, so basically Facebook sometimes doesn't pass a signed request. User's are therefore just being shown a blank screen. If I use code to redirect to the homepage it just gets stuck in an infinite loop. I need the signed request in order to redirect the user accordingly. Is there any reason that Facebook would sometimes not send me a signed request?

If I check the contents of req.body.signed_request it is sometimes empty, so it's not as if the fb module isn't working properly.

0

There are 0 best solutions below