Skip to content

aminkhademian/nookies

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XO code style

nookies 🍪 🍪 🍪

A collection of cookie helpers for Next.js

  • SSR support, for setter, parser and destory
  • super light
  • perfect for authentication

Setting and destorying cookies also works on server-side.

Quick start

import { parseCookies, setCookie, destroyCookie } from 'nookies' 

export default class Me extends React.Component {
   static async getInitialProps(ctx) {
      // Parse
      parseCookies(ctx)

      // Set
      setCookie(ctx, 'token', token, {
         maxAge: 30 * 24 * 60 * 60,
         path: '/'
      })

      // Destory
      destroyCookie(ctx, 'token')
   }

   render() {
      return (
         <div>My profile</div>
      )
   }
}

Reference

parseCookies(ctx, options)

  • ctx: Next.js context
  • options:
    • decode: a custom resolver function (default: decodeURIComponent)

setCookie(ctx, name, value, options)

  • ctx: (Next.js context)
  • name: cookie name
  • value: cookie value
  • options:
    • domain
    • encode
    • expires
    • httpOnly
    • maxAge
    • path
    • sameSite
    • secure

destroyCookie(ctx, name)

  • ctx: (Next.js context)
  • name: cookie name

License

MIT

About

🍪 A set of cookie helpers for Next.js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%