Skip to content

Instantly share code, notes, and snippets.

@itayw
Last active August 29, 2015 14:03
Show Gist options
  • Save itayw/9e444c4b535900633dd8 to your computer and use it in GitHub Desktop.
Save itayw/9e444c4b535900633dd8 to your computer and use it in GitHub Desktop.
Answer to FB question
exports.i_do_something = function(options, callback) {
var result = 'Here we go.';
return callback(null, result);
};
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);
};
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