I'm currently writing a server-centric package for Meteor, and the relevant code looks something like this:
__meteor_bootstrap__.app.stack.unshift({
route: route_final,
handle: function (req,res, next) {
res.writeHead(200, {'Content-Type': 'text/json'});
res.end("Print current user here");
return;
}.future ()
});
This is obviously a relatively hacky way of doing things, but I need to create a RESTful API.
How can I access Meteor.userId()
from here? The docs say it can only be accessed from inside a method or publish. Is there any way around that?
Things I've tried:
- Capture it from a publish using
Meteor.publish("user", function() { user = this.userId() });
- Get the token + user id from the cookies and authenticate it myself using something like
Meteor.users.findOne({_id:userId,"services.resume.loginTokens.token":logintoken});
- Create a method called
get_user_id
and call it from inside my code below.