REST API : How do I DDP.connect as a specific user on the server?


I wanted to have a REST API and create it as a Microapp using DDP.connect . The methods I run need to run as an authenticated user.

I was just using iron router with a server side route… eg:

Router.route('/create', { where: 'server' })
    .get(function () {
        var req = this.request;
        var res = this.response;

        var loginToken = (
            // - using a url parameter
            (this.params && this.params.query && this.params.query.loginToken) ||
                // - using a cookie
            (this.request && this.request.cookies && this.request.cookies.loginToken)

        var hashedLoginToken = Accounts._hashLoginToken(loginToken);
        // Possibly get the user
        var user = Meteor.users.findOne({
            "services.resume.loginTokens.hashedToken": hashedLoginToken
        //to get logintoke in browser use Accounts._storedLoginToken()"createTest",user._id)

        res.end('hello from the server\n')

So when I call the methods from my REST APP, it find the user based on the logintoken and then proceeds to call the method, which is on the server:

    createTest: function(userID){
        var logConn = DDP.connect("http://localhost:3000");

I get Error: Can't call setUserId on a server initiated method call

Is there a way to do this? Any ideas, pls?

Looks like this will solve the issue:

Thanks @sashko via

Also had found