Skip to content

icsfl/connect-dynamodb

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

75 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Connect DynamoDB

connect-dynamodb is a DynamoDB session store backed by the aws-sdk

NPM NPM

Installation

  $ npm install connect-dynamodb

What is different in this fork?

  • This fork was created to add a specific and somewhat-unique feature around making sure that a given user only has one active session. This works by exposing a new method on the store called destroyOtherSessionsForUser. This would then be called by your passport code post-login to effectively kill all other sessions that the user has. Our specific use-case is around named-user licensing.
  • It has a loose dependency on passport.
  • When creating the dynamodb table, it specifies a range key for the user, and a global secondary index that has the user has the hash key and the session id as the range key. The index is used to query/lookup all session by user.

Options

  • One of the following:
  • AWSRegion Optional AWS region (defaults to 'us-east-1', ignored if using AWSConfigPath or AWSConfigJSON)
  • table Optional DynamoDB server session table name (defaults to "sessions")
  • hashKey Optional hash key (defaults to "id")
  • rangeKey Optional (defaults to "user")
  • prefix Optional key prefix (defaults to "sess")
  • reapInterval Optional - how often expired sessions should be cleaned up (defaults to 600000)
  • userPath Optional - the "property path" to determine the current user in the session object. For example, when using passport, it would be the string passport.user

Usage

var options = {
	// Name of the table you would like to use for sessions.
	// Defaults to 'sessions'
  	table: 'myapp-sessions',

	// Optional path to AWS credentials (loads credentials from environment variables by default)
  	// AWSConfigPath: './path/to/credentials.json',

	// Optional JSON object of AWS configuration options
  	// AWSConfigJSON: {
  	//     region: 'us-east-1',
  	//     correctClockSkew: true
  	// }

  	// Optional. How often expired sessions should be cleaned up.
  	// Defaults to 600000 (10 minutes).
  	reapInterval: 600000
};

var connect = require('connect'),
	DynamoDBStore = require('connect-dynamodb')(connect);
connect()
	.use(connect.cookieParser())
	.use(connect.session({ store: new DynamoDBStore(options), secret: 'keyboard cat'}))

Or with express 3.x.x

DynamoDBStore = require('connect-dynamodb')(express);
var app = express(
	express.cookieParser(),
	express.session({ store: new DynamoDBStore(options), secret: 'keyboard cat'})
);

Or with express 4.x.x

var app = express();
var session = require('express-session');
DynamoDBStore = require('connect-dynamodb')({session: session});
app.use(session({ store: new DynamoDBStore(options), secret: 'keyboard cat', resave: true, saveUninitialized: true}));

Contributors

Some people that have added features and fixed bugs in connect-dynamodb other than me.

Thanks!

License

connect-dynamodb is licensed under the MIT license.

Donations

I made this in my spare time, so if you find it useful you can donate at my BTC address: 13Bzg4reJJt43wU1QsPSCzyFZMLhJbRELA. Thank you very much!

Packages

No packages published

Languages

  • JavaScript 98.1%
  • Makefile 1.9%