Skip to content

Commit

Permalink
fix: ts typings
Browse files Browse the repository at this point in the history
Update typing to support nextjs api routes
  • Loading branch information
maticzav authored Apr 24, 2020
2 parents 9755067 + efeb7fc commit ce58f61
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ function createCookie(
* @param options
*/
export function parseCookies(
ctx?: Pick<next.NextPageContext, 'req'> | null | undefined,
ctx?:
| Pick<next.NextPageContext, 'req'>
| { req: next.NextApiRequest }
| null
| undefined,
options?: cookie.CookieParseOptions,
) {
if (ctx && ctx.req && ctx.req.headers && ctx.req.headers.cookie) {
Expand All @@ -104,7 +108,11 @@ export function parseCookies(
* @param options
*/
export function setCookie(
ctx: Pick<next.NextPageContext, 'res'> | null | undefined,
ctx:
| Pick<next.NextPageContext, 'res'>
| { res: next.NextApiResponse }
| null
| undefined,
name: string,
value: string,
options: cookie.CookieSerializeOptions,
Expand Down Expand Up @@ -134,9 +142,9 @@ export function setCookie(

if (isBrowser()) {
if (options && options.httpOnly) {
throw new Error("Can not set a httpOnly cookie in the browser.")
throw new Error('Can not set a httpOnly cookie in the browser.')
}

document.cookie = cookie.serialize(name, value, options)
}

Expand All @@ -152,7 +160,11 @@ export function setCookie(
* @param options
*/
export function destroyCookie(
ctx: next.NextPageContext | null | undefined,
ctx:
| Pick<next.NextPageContext, 'res'>
| { res: next.NextApiResponse }
| null
| undefined,
name: string,
options?: cookie.CookieSerializeOptions,
) {
Expand Down

0 comments on commit ce58f61

Please sign in to comment.