Skip to content

Instantly share code, notes, and snippets.

@themeteorchef
Created March 1, 2016 14:45
Show Gist options
  • Save themeteorchef/5dc7af10e25770777a9f to your computer and use it in GitHub Desktop.
Save themeteorchef/5dc7af10e25770777a9f to your computer and use it in GitHub Desktop.
Execute If Allowed
Meteor.methods({
authorizedMethod() {
Modules.server.executeIfAllowed( [ 'admin', 'manager' ], () => {
// Some secure task to complete here.
});
}
});
// Relying on a global here but you could use export/import in 1.3 just the same.
Modules.server.executeIfAllowed = ( roles, callback ) => {
if ( Roles.userIsInRole( Meteor.userId(), roles ) ) {
callback();
} else {
throw new Meteor.Error( '500', 'Sorry. You\'re not allowed to do that!' );
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment