mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
Merge branch 'Ragg--improve-koa-generic-session-typing'
This commit is contained in:
Vendored
+11
-1
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user