Skip to content

Commit

Permalink
Docs(api-middlewares): use typings for serialize options from @types/…
Browse files Browse the repository at this point in the history
…cookie (#17285)
  • Loading branch information
geritol authored Sep 22, 2020
1 parent beeeba0 commit 8fdb93d
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions docs/api-routes/api-middlewares.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,18 @@ For better type-safety, it is not recommended to extend the `req` and `res` obje
```ts
// utils/cookies.ts

import { serialize } from 'cookie'
import { serialize, CookieSerializeOptions } from 'cookie'
import { NextApiResponse } from 'next'

/**
* This sets `cookie` using the `res` object
*/

type Options = {
expires?: Date
maxAge?: number
}

export const setCookie = (
res: NextApiResponse,
name: string,
value: unknown,
options: Options = {}
options: CookieSerializeOptions = {}
) => {
const stringValue =
typeof value === 'object' ? 'j:' + JSON.stringify(value) : String(value)
Expand Down

0 comments on commit 8fdb93d

Please sign in to comment.