Secbone / koa-session2

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

How to destroy session? #30

Closed OuyangMr closed 7 years ago

OuyangMr commented 7 years ago

I got this error when try to destroy a session: TypeError: ctx.session.destroy is not a function app: ctx.session.destroy();

Why not give a destroy()method to Session? And how can I destroy a session simply?

OuyangMr commented 7 years ago

As your code has a destory strategy: `// if not changed if(old == JSON.stringify(ctx.session)) return;

    // clear old session if exists
    if(id) {
        await store.destroy(id);
        // set it to undefined instead of null to be able to use default parameters at Store
        id = undefined;
    }`

I resolve it by using ctx.session = {};

Secbone commented 7 years ago

@OuyangMr you can set session a null or empty string or something false, it will be destroyed. 😄