Ну, что было легко.
Meteor.user()
и Meteor.userId()
доступны на сервере так же, как и на клиенте - безопасно управляются и проверяются ядром Meteor.
Kudos Meteor team!
Meteor.methods({
myFancyFunc1: function(args) {
var user = Meteor.user();
},
myFancyFunc2: function(args) {
var user = AbstractClass.getUser();
}
});
AbstractClass = {
getUser: function() {
if (Meteor.isServer) {
// are we initiated via DDP (with access to Auth, Meteor.call)
var currentInvocation = DDP._CurrentInvocation.get();
if (currentInvocation) {
// return logged in user as passsed through
return Meteor.user();
}
// we don't know the user details, return empty object instead
return {};
}
}
};