Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Object [object Object] has no method 'createUser' #169

Closed
Anearion opened this issue Jan 19, 2016 · 4 comments
Closed

TypeError: Object [object Object] has no method 'createUser' #169

Anearion opened this issue Jan 19, 2016 · 4 comments
Labels

Comments

@Anearion
Copy link

Hi everyone, I'm sorry if this could be imputed to my newbiness, but I'm really new to nodejs/meteor world.

By the way, I'm trying to implementate you example but im getting the error in the title if I try to do a post request to /api/users, passing your example json as argument.

Code is a copy&paste of your, and surfing the internet didn't help me finding a solution.

That's full error:

TypeError: Object [object Object] has no method 'createUser'
at Object.post.action (packages/nimble_restivus/packages/nimble_restivus.js:850:1)
at Route.Route._callEndpoint (packages/nimble_restivus/packages/nimble_restivus.js:318:1)
at packages/nimble_restivus/packages/nimble_restivus.js:209:1
at packages/simple_json-routes/packages/simple_json-routes.js:53:1

@kahmali
Copy link
Owner

kahmali commented Jan 19, 2016

Please provide a sample repository demonstrating the issue, or clear reproduction steps. There's just not enough information there for me to help you. You may have better luck getting these troubleshooting questions answered on Stack Overflow (with more information provided there as well), as it's likely not an issue with Restivus, but the way you're using it. It could take me a month or longer before I have time to do this sort of troubleshooting. Sorry!

@Anearion
Copy link
Author

Sure, sorry but i thoughti was clear enough.

I just used your sample server code, that of course now has some changes, but this didn't cause the problem as i had it just after the copy and paste:

Items = new Mongo.Collection('items');
Articles = new Mongo.Collection('articles');
Rooms = new Mongo.Collection('rooms');
Messages = new Mongo.Collection('messages');

if (Meteor.isServer) {

var Message = {
  _id:0,
  message:"",
  type:"",
  sender:""
};

// Global API configuration
var Api = new Restivus({
  useDefaultAuth: true,
  prettyJson: true
});

// Generates: GET, POST on /api/items and GET, PUT, DELETE on
// /api/items/:id for the Items collection
Api.addCollection(Items);

Api.addCollection(Rooms);

Api.addCollection(Messages, {
  get: function(){

  },
  post: function(){

  }

});

// Generates: POST on /api/users and GET, DELETE /api/users/:id for
// Meteor.users collection
Api.addCollection(Meteor.users, {
  routeOptions: {
    authRequired: false
  },
  endpoints: {
    post: {
      authRequired: false
    },
    delete: {
      roleRequired: 'admin'
    }, 
    post: function(){
      Accounts.createUser({
        username: username,
        email : email,
        password : password
      });
    }
  }
});

// Maps to: /api/articles/:id
Api.addRoute('articles/:id', {authRequired: true}, {
  get: function () {
    return Articles.findOne(this.urlParams.id);
  },
  delete: {
    roleRequired: ['author', 'admin'],
    action: function () {
      if (Articles.remove(this.urlParams.id)) {
        return {status: 'success', data: {message: 'Article removed'}};
      }
      return {
        statusCode: 404,
        body: {status: 'fail', message: 'Article not found'}
      };
    }
  }
});

}

Basically if i test the /api/users endpoint, with a POST request in postman it gives me the following error:

TypeError: Object [object Object] has no method 'createUser'
at Object.post.action (packages/nimble_restivus/packages/nimble_restivus.js:850:1)
at Route.Route._callEndpoint (packages/nimble_restivus/packages/nimble_restivus.js:318:1)
at packages/nimble_restivus/packages/nimble_restivus.js:209:1
at packages/simple_json-routes/packages/simple_json-routes.js:53:1

All others endpoints are generated correctly so i guess is something to do with Meteor.users collection itself, but I can't undestand what I'm doing different from your example, as this works for all other people.

Am i missing some dependecies or external libs ?

@kahmali
Copy link
Owner

kahmali commented Jan 26, 2016

Unfortunately it wasn't clear enough, or I wouldn't have asked for clarification :)

There's a lot of sample code in the docs, so I had no idea what you were talking about. It appears you were referring to the quick start example code. That's definitely a bug, so thanks for reporting it! I'm just shocked that no other Restivus user has bumped into this issue. Or maybe they have and they just weren't awesome enough as you to report it :)

I believe what will fix it for you is just including the accounts-password package in your app, but that shouldn't be necessary. Restivus should declare the dependency itself, as it does use it directly when the Meteor.users collection endpoints are added. I wish there were a way to conditionally require packages. I really only want it to load when folks want endpoints on their Meteor.users collection, but I guess the only option is to require the dependency for everyone. This is why I really need to break all this accounts stuff out of Restivus core asap. It's getting a little "heavy" for users that only need the basic functionality. I have dreams of making this a lot more like Astronomy in its modularity (although I've been saying that for nearly a year and I still haven't gotten around to it, shame on me).

I'll get this update taken care of asap. I'll try to have it ready no later than tomorrow. Feel free to follow up if you don't hear from me by then. Sorry for the delayed response. I'm broke and trying to maintain a production app, so I literally can't afford to work on Restivus a lot anymore.

@kahmali
Copy link
Owner

kahmali commented Feb 24, 2016

I just published v0.8.7 with the fix for this. Sorry it took so long. Feel free to reopen the issue if the problem persists after updating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants