Merge branch 'Ragg--improve-koa-generic-session-typing'

This commit is contained in:
Andy Hanson
2017-06-02 07:28:03 -07:00
2 changed files with 23 additions and 1 deletions
+11 -1
View File
@@ -1,13 +1,15 @@
// Type definitions for koa-generic-session 1.x
// Project: https://github.com/koajs/generic-session
// Definitions by: Nick Simmons <https://github.com/nsimmons/>
// Definitions by: Nick Simmons <https://github.com/nsimmons/>, Ragg <https://github.com/Ragg-/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import * as Koa from "koa";
declare namespace koaSession {
interface Session {
cookie: any;
[key: string]: any;
}
interface SessionIdStore {
@@ -50,5 +52,13 @@ declare namespace koaSession {
const MemoryStore: SessionStore;
}
declare module 'koa' {
interface Context {
session: koaSession.Session|null;
sessionSave: boolean|null;
regenerateSession(): Generator;
}
}
declare function koaSession(options: koaSession.SessionOptions): Koa.Middleware;
export = koaSession;
@@ -32,4 +32,16 @@ app.use(session({
beforeSave: (ctx: Koa.Context, session: Session) => {}
}));
app.use((context: Koa.Context) => {
if (! context.session) {
return;
}
context.regenerateSession();
context.sessionSave = true;
context.session.cookie;
context.session['key'] = 'value';
context.session = null;
});
app.listen(80);