Hello,
I’m figuring out how to detect an operation e.g. “insert” by system or by Meteor it self, not by user via browser.
Meteor.methods({
insertCustomer: function(post) {
if (!this.userId) {
throw new Meteor.Error('customers.insertCustomer.notLoggedIn',
'Must be logged in.');
}
Customers.insert(post);
}
});
If i call that method above from e.g startup.js
:
const customers = [
{
firstname: 'John',
lastname: 'Doe',
},
{
firstname: 'Merry',
lastname: 'Anne',
},
];
users.forEach((customer) => {
Meteor.call('insertCustomer', customer);
}
It will return an error “Must be logged in.” because Meteor.userId
will be null if i call that method from startup.js
Q: My question is how to run “insertCustomer” method with condition “if user is loged in” or “it is called by system or Meteor it self”?
Thanks for some help on this
Ken