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.
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>
)
}
}
- ctx:
Next.js context
- options:
- decode:
a custom resolver function (default: decodeURIComponent)
- decode:
- ctx:
(Next.js context)
- name: cookie name
- value: cookie value
- options:
- domain
- encode
- expires
- httpOnly
- maxAge
- path
- sameSite
- secure
- ctx: (Next.js context)
- name: cookie name
MIT