Created
February 15, 2015 21:37
-
-
Save ndreckshage/1467605f0b833cc9c013 to your computer and use it in GitHub Desktop.
bad auth for shared js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var currentUser; | |
module.exports.get = function() { | |
return currentUser; | |
}; | |
module.exports.set = function(user) { | |
currentUser = user; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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