Secbone / koa-session2

Middleware for Koa2 to get/set session
MIT License
152 stars 30 forks source link

Error when delete session #34

Closed xiedacon closed 7 years ago

xiedacon commented 7 years ago

when i delete session by

ctx.session = null

it throws

TypeError: Cannot convert undefined or null to object

and fix it

// if is an empty object
if(ctx.session !== null && typeof ctx.session === 'object' && !Object.keys(ctx.session).length) {
  ctx.session = null;
}
Secbone commented 7 years ago

@xiedacon I think instanceof is a better way to fix this bug. Also thanks for your PR! 😄

xiedacon commented 7 years ago

that's right, instanceof is much better