Created
March 1, 2016 14:45
-
-
Save themeteorchef/5dc7af10e25770777a9f to your computer and use it in GitHub Desktop.
Execute If Allowed
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
Meteor.methods({ | |
authorizedMethod() { | |
Modules.server.executeIfAllowed( [ 'admin', 'manager' ], () => { | |
// Some secure task to complete here. | |
}); | |
} | |
}); |
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
// 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