Code Monkey home page Code Monkey logo

koa-cookies's Introduction

koa-cookies

Set, clear, and parse cookies in your Koa application.

Donate


Installation

npm i koa-cookies

Usage

// set up your koa server, koa-router, etc.
import { clearCookie, setCookie, parseCookie } from 'koa-cookies'

// Use in routes
app.get('/foo', async (ctx, next) => {
  await setCookie('bar', 'baz')(ctx) // => void
})
app.get('/things', async (ctx) => {
  await clearCookie('foo')(ctx) // => void
})
app.get('/stuff', async (ctx) => {
  await parseCookie('bar')(ctx) // => string value for this cookie key
})

// Use as middlewares
app.use(setCookie('foo', 'bar', config)) // set on every request
app.use(clearCookie('baz', config)) // clear on every request
app.use(parseCookie()) // always add all cookies to ctx.cookies

The config argument is optional. Defaults:

setCookieConfig = {
  domain: ctx.host,
  maxAge: one week,
  expires: one week from now
}

clearCookieConfig = {
  domain: ctx.host,
  maxAge: 1 second,
  expires: 1970-01-01T00:00:00.001Z
}

LICENSE

koa-cookies's People

Contributors

dependabot[bot] avatar zacanger avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

koa-cookies's Issues

Does it support the UTF-8?

(node:16500) UnhandledPromiseRejectionWarning: TypeError: argument value is invalid
at new Cookie (E:\nodekoa\node_modules\cookies\index.js:125:11)
at Cookies.set (E:\nodekoa\node_modules\cookies\index.js:88:16)
at E:\nodekoa\node_modules\koa-cookies\index.js:17:17
at login (E:\nodekoa\controller\homeController.js:24:55)
(node:16500) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:16500) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.