A Felid plugin that provides support for cookies.
npm install felid-cookie
or
yarn add felid-cookie
const Felid = require('felid')
const cookie = require('felid-cookie')
const app = new Felid()
app.plugin(cookie, options)
app.get('/', (req, res) => {
const cookies = req.cookies // cookies from client
req.unsign('signed cookie') // unsign the request cookie
res.cookie('cookie key', 'cookie value') // set a single cookie pair
res.cookies({ foo: 'bar' }) // set cookies
})
- secret String: The default secret key for cookies signature. If a non-empty secret has been set, the cookie will be signed.
- unsign Boolean: Unsign the request cookies automatically if a secret key is given. You can manually unsign the cookie by invoking
request.unsign()
if this option is set tofalse
. Default isfalse
. - parseOptions Object: The options for cookie.parse().
- decorator Object: Customize the decorator names. Default is:
{
reqGetCookie: 'cookies',
unsignCookie: 'unsign',
resSetCookie: 'cookie',
resSetCookies: 'cookies'
}
For more options, please check cookie.
Some has default values:
- httpOnly: true
- request.cookies: The parsed request cookies.
- request.unsign(key: String, secret?: String): Unsign the given cookie pair. The secret passed here will override the plugin secret.
- response.cookie(key: String, value: String, options?: Object): Set a single cookie pair. The options passed here will override the plugin options.
- response.cookies(cookies: Object, options?: Object): Set a set of cookie pairs. The options passed here will override the plugin options.