Skip to content

Commit

Permalink
Allow to pass initial data to create a session if it doesn't exist on…
Browse files Browse the repository at this point in the history
… http request (#5)
  • Loading branch information
dresende committed Jan 8, 2013
1 parent e7899d0 commit d6f10bb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,16 @@ Sessions.prototype.create = function () {
Sessions.prototype.uid = function () {
return String(Math.random()).substr(2) + String(Math.random()).substr(2);
};
Sessions.prototype.httpRequest = function (req, res, cb) {
Sessions.prototype.httpRequest = function (req, res, data, cb) {
var cookies = parseCookies(req),
sessions = this;

if (typeof data == "function") {
cb = data;
}

if (!cookies.hasOwnProperty("uid")) {
return this.create(function (err, session) {
return this.create(data || {}, function (err, session) {
if (err) {
return cb(err);
}
Expand Down

0 comments on commit d6f10bb

Please sign in to comment.