Skip to content

Instantly share code, notes, and snippets.

@ndreckshage
Created February 15, 2015 21:37
Show Gist options
  • Save ndreckshage/1467605f0b833cc9c013 to your computer and use it in GitHub Desktop.
Save ndreckshage/1467605f0b833cc9c013 to your computer and use it in GitHub Desktop.
bad auth for shared js
// even though the dangerous auth is fine on client
var cu = require('dangerous-auth').get();
// need to instead shim a context to maintain same api
// to resolve routes etc, sometime need access to context
// var context = {};
var currentUser;
module.exports.get = function() {
return currentUser;
};
module.exports.set = function(user) {
currentUser = user;
}
// this is dangerous on server, since node shares / caches variables
app.use(function(req, res) {
require('dangerous-auth').set({ name: 'nick' });
// ...
});
// instead you should use context
app.use(function(req, res) {
req.context = req.context || {};
req.context.currentUser = { name: 'nick' };
// ...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment