Skip to content

Commit

Permalink
Merge pull request #78 from emersonmellado/master
Browse files Browse the repository at this point in the history
Adjusting expiration time to be 7 days
  • Loading branch information
nelsonic committed Oct 16, 2017
2 parents 6377f0c + c7a24e2 commit 660e2e0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
8 changes: 4 additions & 4 deletions example/lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ function generateToken(req, GUID, opts) {
// By default, expire the token after 7 days.
// NOTE: the value for 'exp' needs to be in seconds since
// the epoch as per the spec!
var expiresDefault = Math.floor(new Date().getTime()/1000) + 7*24*60*60;
var expiresDefault = '7d';

var token = jwt.sign({
auth: GUID,
agent: req.headers['user-agent'],
exp: opts.expires || expiresDefault
}, secret);
agent: req.headers['user-agent']
}, secret, { expiresIn: expiresDefault });

return token;
}

Expand Down
16 changes: 9 additions & 7 deletions example/server.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
var port = process.env.PORT || 1337; // let heroku define port or use 1337
var http = require('http'); // core node.js http (no frameworks)
var url = require('url'); // core node.js url (no frameworks)
var app = require('./lib/helpers'); // auth, token verification & render helpers
var c = function(res){ /* */ };

http.createServer(function (req, res) {
var url = req.url;
if( url === '/' || url === '/home' ) { app.home(res); } // homepage
else if( url === '/auth') { app.handler(req, res); } // authenticator
else if( url === '/private') { app.validate(req, res, app.done); } // private content
else if( url === '/logout') { app.logout(req, res, app.done); } // end session
else if( url === '/exit') { app.exit(res); } // for testing ONLY
else { app.notFound(res); } // 404 error
var path = url.parse(req.url).pathname;
if( path === '/' || path === '/home' ) { app.home(res); } // homepage
else if( path === '/auth') { app.handler(req, res); } // authenticator
else if( path === '/private') { app.validate(req, res, app.done); } // private content
else if( path === '/logout') { app.logout(req, res, app.done); } // end session
else if( path === '/exit') { app.exit(res); } // for testing ONLY
else { app.notFound(res); } // 404 error
}).listen(port);

console.log("Visit: http://127.0.0.1:" + port);

0 comments on commit 660e2e0

Please sign in to comment.