Is there any way to do a server Meteor.call('mymethod')
and pass through this
or at least this.userId
?
With a validated method, you can _execute()
and pass in a context link
This is something I need to accomplish the following:
- from a client&server accessible validated-method
- when running on the server
- also call a different server-only method.
The problem is, I can not import the server only method into shared code and call it directly.
And I can not expose a server only method without authentication / security.
So how do I get a server-side “trusted” secure userId
to pass through to another server method?
// is common (both server and client)
const MSchema = new SimpleSchema({
a: {
label: 'Argument',
type: String,
optional: true,
},
});
const M0 = new ValidatedMethod({
name: 'MethodUserIdTesting',
mixins: [simpleSchemaMixin],
schema: MSchema,
schemaValidatorOptions: { clean: true, filter: true },
run: function m0(params) {
console.log('M0', params.a, this.userId);
Meteor.call('M1', params.a);
},
});
// isServer
Meteor.methods({
M1: function m1(a) { check(a, String); console.log('M1', a, this.userId); Meteor.call('M2', a); },
M2: function m2(a) { check(a, String); console.log('M2', a, this.userId); },
});
// isClient & authenticated
M0.call({ a: 'I wish userId would just pass through' });
Meteor.call('M1', 'I wish userId would just pass through');