mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-05 07:17:04 +00:00
Typing koa.Context for koa-generic-session
This commit is contained in:
Vendored
+10
-1
@@ -1,6 +1,6 @@
|
||||
// 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
|
||||
|
||||
import * as Koa from "koa";
|
||||
@@ -8,6 +8,7 @@ import * as Koa from "koa";
|
||||
declare namespace koaSession {
|
||||
interface Session {
|
||||
cookie: any;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
interface SessionIdStore {
|
||||
@@ -50,5 +51,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);
|
||||
|
||||
Reference in New Issue
Block a user