dispatch:run-as-user
Allow server and client to run as user in restricted mode.
API:
Meteor.runAsUser(userId, func)
Meteor.restricted()
Examples
1 Meteor.runAsUser(userId, function() { 2 // Run method as user on both client or server 3 Meteor.call('getUserId'); 4 });
Client cannot set other userId that it's current user
1 foo = new Mongo.Collection('foo-collection'); 2 3 foo.allow({ 4 insert: function(userId) { return !!userId; } 5 }); 6 7 Meteor.runAsUser(userId, function() { 8 // This will throw errors on both client and server if 9 // not allowed 10 foo.insert({ name: 'foo'}); 11 });
1 Meteor.runAsUser(userId, function() { 2 if (Meteor.isRestricted()) { 3 // Something in restricted mode 4 console.log(Meteor.userId()); 5 } else { 6 // Safe mode 7 } 8 });