user3934417
user3934417

Reputation: 41

How to disable cookies using sails js

I need to remove all cookies of sails js, but i didn't find documentation. The problem is that the authentication is with token and no with cookies however the cookie is generated when make a request to the server in sails js. I need disabled creation of cookies in sails. Thanks

Upvotes: 4

Views: 2037

Answers (4)

Premjeet
Premjeet

Reputation: 320

Try this one, It works for me:

Set Cookie

res.cookie('cookieName', "cookieValue", { expires: new Date(Date.now() + 300000), httpOnly: true, signed: true });


Get Cookie

req.signedCookies.cookieName;


Delete Cookie

res.clearCookie('cookieName');

Upvotes: 4

leompeters
leompeters

Reputation: 1035

You can disable sessions in Sails, that should disable cookies. Add the code below in your .sailsrc:

{
  ...
  "hooks": {
    "session": false
  }
}

Source: http://sailsjs.org/documentation/reference/configuration/sails-config-session#?disabling-sessions

Upvotes: 4

Fabien Gane
Fabien Gane

Reputation: 76

delete req.cookies.rememberme 

Won't work like with sessions.

You can replace it by a null value :

res.cookie('rememberme', null);

Then, check if the cookie isn't null

Upvotes: 0

Xinzz
Xinzz

Reputation: 2252

Have you looked into this issue on github?

https://github.com/balderdashy/sails/issues/841

You may implement what sgress454 suggested in the comments on the thread to get rid of cookies -- you might also need to remove some middleware such as session.

Upvotes: 0

Related Questions