I am using Cookies module for setting cookie. Here is following my code:
var options = { maxAge: ALMOST_ONE_HOUR_MS, domain: '.test.com', expires: new Date(Date.now() + ALMOST_ONE_HOUR_MS) }; var value = userInfo.token; cookies.set("testtoken", value, options);
But in documentation I haven't found how to destroy this cookie.
Any suggestion would be appreciated.
There is no way to delete a cookie according to the HTTP specification. To effectively "delete" a cookie, you set the expiration date to some date in the past.
Destroying cookies is upto the browser however you can remove a cookie (which is the same for your app) by setting the date in the past: setcookie($cookie_name, "", 1); Most set the time to 1970 .
The res. clearCookie() function is used to clear the cookie specified by name. This function is called for clearing the cookies which as already been set. For example if a user cookie is set, then it can be cleared using this function.
Deleting Existing Cookies To delete a cookie, use the clearCookie function. For example, if you need to clear a cookie named foo, use the following code. var express = require('express'); var app = express(); app. get('/clear_cookie_foo', function(req, res){ res.
For webapp you can just set cookie in response as :
res.cookie("key", value);
and to delete cookie :
res.clearCookie("key");
and don't forget to:
res.end()
to avoid the web request hanging.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With