Skip to content

Commit

Permalink
fix: Types, Set-Cookie header on destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
maticzav committed Jul 18, 2019
1 parent 6900eb0 commit 12b2cf5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function parseCookies(
ctx?: next.NextContext | null | undefined,
options?: cookie.CookieParseOptions,
) {
if (ctx && ctx.req && ctx.req.headers.cookie) {
if (ctx && ctx.req && ctx.req.headers && ctx.req.headers.cookie) {
return cookie.parse(ctx.req.headers.cookie as string, options)
}

Expand All @@ -84,7 +84,7 @@ export function setCookie(
value: string,
options: cookie.CookieSerializeOptions,
) {
if (ctx && ctx.res) {
if (ctx && ctx.res && ctx.res.getHeader && ctx.res.setHeader) {
let cookies = ctx.res.getHeader('Set-Cookie') || []

if (typeof cookies === 'string') cookies = [cookies]
Expand Down Expand Up @@ -134,8 +134,8 @@ export function destroyCookie(
) {
const opts = { ...(options || {}), maxAge: -1 }

if (ctx && ctx.res) {
let cookies = ctx.res.getHeader('set-cookie') || []
if (ctx && ctx.res && ctx.res.setHeader && ctx.res.getHeader) {
let cookies = ctx.res.getHeader('Set-Cookie') || []

if (typeof cookies === 'string') cookies = [cookies]
if (typeof cookies === 'number') cookies = []
Expand Down

0 comments on commit 12b2cf5

Please sign in to comment.