- Notifications
You must be signed in to change notification settings - Fork0
MongoDB backed session middleware for Koa
License
aheckmann/koa-session-mongodb
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
MongoDB backed session middleware for Koa.js
This module currently suffers from a memory leak due to its reliance on theobserved module. You probably want to usethis module instead while we wait for v8 to fix thememory leak.
$npminstallkoa-session-mongodb
View counter example:
varsession=require('koa-session-mongodb');varmongo=require('mongodb').MongoClient;varkoa=require('koa');mongo.connect(uri,function(err,db){if(err)throwerr;varapp=koa();app.keys=['some secret'];app.use(session({collection:db.collection('session')}));app.use(function*(){varn=this.session.views||0;this.session.views=++n;this.body=n+' views';})app.listen(3000);console.log('listening on port 3000');})
This module provides "guest" sessions, meaning any visitor will have a session,authenticated or not. If a session isnew a Set-Cookie will be produced regardlessof populating the session.
The cookie name is controlled by thekey option, which defaultsto "sid". All other options are passed toctx.cookies.get() andctx.cookies.set() allowing you to control security, domain, path,and signing among other settings.
Returnstrue if the session is new.
To destroy a session simply set it tonull:
this.session=null;
About
MongoDB backed session middleware for Koa
Resources
License
Uh oh!
There was an error while loading.Please reload this page.