Last active
August 29, 2015 14:03
-
-
Save itayw/9e444c4b535900633dd8 to your computer and use it in GitHub Desktop.
Answer to FB question
This file contains hidden or 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
exports.i_do_something = function(options, callback) { | |
var result = 'Here we go.'; | |
return callback(null, result); | |
}; |
This file contains hidden or 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
exports.check_has_permission = function(user, callback) { | |
//do the work needed with the db to check user has permission for action | |
var validated = your_actual_check(); | |
if (!validated) | |
return callback(new Error('Authentication failed')); | |
return callback(null, true); | |
}; |
This file contains hidden or 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 auth = require('./auth.js'); | |
exports.web_function = function(req, res) { | |
var user = req.params.user; | |
return auth.check_has_permission (user, function(err, validated) { | |
if (err) //failed auth | |
return res.end('error: ' + err); | |
//passed auth | |
var _module = require('your external module'); | |
return _module.i_do_something({/* want to pass anything? */}, function(err, result) { | |
if (err) | |
return res.end('error: ' + err); | |
return res.end('OK: ' + result); | |
}); | |
}); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment