Express-JWT is just a library for Express that validates/signs json web tokens whcih can be used with the express web server (middleware). JsonWebTokens is just another implementation of json web tokens. There are many other JWT token libraries you can implement with node. Express-jwt is just one of those. They both essentially do the same thing and you can use either or. None are built on top of each other, they are build using the JWT standard. Choose the one which best suites your requirements.
https://stackoverflow.com/questions/20612275/how-to-use-req-session-data-in-an-other-javascript-file-expressjs
https://stackoverflow.com/questions/20612275/how-to-use-req-session-data-in-an-other-javascript-file-expressjs
This is not possible with your current setup without a lot of hacking. Each session is reliant on the user's SID found in the request's cookie. Thus, the session is strongly coupled to the request object. You will have to find a clever way to initialize your
game.js
module through middleware. Something like:var Game = require('./game');
// -- Place this AFTER your session middleware
app.use(function (req, res, next) {
req.game = new Game(req);
next();
});
And then inside of
game.js
var Game = module.exports = function (req) {
// do stuff with req.session here
this.req = req;
}
Game.prototype.getSessionID = function () {
return this.req.session.uid;
}
Hope that helps you get there. My honest opinion is that you might want to reconsider your design as your modules that don't work with the request object directly shouldn't be tightly coupled with the request object.
Comments
Post a Comment