felid-cookie

1.1.0 • Public • Published

felid-cookie

npm version Build Status JavaScript Style Guide

A Felid plugin that provides support for cookies.

Install

npm install felid-cookie

or

yarn add felid-cookie

Usage

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
})

Options

  • 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 to false. Default is false.
  • 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

Api

  • 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.

License

MIT

Package Sidebar

Install

npm i felid-cookie

Weekly Downloads

1

Version

1.1.0

License

MIT

Unpacked Size

6.8 kB

Total Files

4

Last publish

Collaborators

  • zoron