7

I'm trying to add facebook login to my site. I've authenticated with facebook JavaScript SDK and created a cookie with user id. The problem is that when user logs out (I'm destroying all cookies) and navigates to another page on site, I can still see cookie with data.

Below are the functions, I'm using to create and destroy cookies:

Utils.createSessionCookie = function(id, name, access_token) {    
    if (Utils.getCookie(Consts.USER_ID) == null) {
        Utils.setCookie(Consts.USER_ID, id, 1);
        Utils.setCookie(Consts.NAME, name, 1);
        Utils.setCookie(Consts.ACCESS_TOKEN, access_token, 1);
    }
};

Utils.destroySessionCookie = function() {
    Utils.setCookie(Consts.USER_ID, '', -1);
    Utils.setCookie(Consts.NAME, '', -1);
    Utils.setCookie(Consts.ACCESS_TOKEN, '', -1);
};

Utils.setCookie = function(name, value, days) {
    var expireDate = new Date();
    expireDate.setDate(expireDate.getDate() + days);
    var cookieValue = escape(value) + ((days == null) ? "" : ";expires=" + expireDate.toUTCString() + "; path=/");
    document.cookie = name + "=" + cookieValue;
};
Toon Krijthe
  • 52,876
  • 38
  • 145
  • 202
  • 1
    got it solved..was having a bug in code that was repeatedly creating the cookie. – Anand Mohan Nov 09 '12 at 15:25
  • 9
    I seriously don't hope you are using these cookies for authentication, you realize any user can create the same cookies, with arbitrary values right? – Sean Kinsey Nov 17 '12 at 04:04
  • 16
    If you have solved your problem, could you please answer your own question? Thanks :) – NT3RP Nov 26 '12 at 23:42

1 Answers1

1

Note: Just help answering OP's question.

According to the comments above, there is a bug in user-created codes that repeatedly creating the cookie. It is not Facebook SDK's bugs.

After solving the bug, the Facebook cookies work fine.

Raptor
  • 53,206
  • 45
  • 230
  • 366