0

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.

prabir
  • 7,674
  • 4
  • 31
  • 43
Craig Myles
  • 5,206
  • 3
  • 40
  • 37
  • Well that's the thing - req.body.signed_request is undefined. So the module has no signed request to process – Craig Myles Nov 28 '12 at 23:49
  • Since it's a `HTTP POST`, sometimes it gets lost in redirects. Is anything like that happening? – Colm Doyle Nov 29 '12 at 00:06
  • Quite possibly. If a user doesn't like our page we redirect them to a page that encourages them to like it (the merits of this need not be discussed here). Once they like the page it automatically reloads the homepage, and it looks like it is here that sometimes the signed request isn't present. But sometimes it is, so there seems to be no concrete pattern? – Craig Myles Nov 29 '12 at 01:15

0 Answers0