15107

Restivus authentication for Meteor methods

Question:

I'm trying to make my meteor-app for REST services available. For this I use the package "Restivus" which also works just fine. But once I'd like to run a meteor method this.userId is undefined.

Api.addRoute('addArticle', {authRequired: true}, { post: function () { console.log(this.userId); //<-- hwuqtFXf8aKperJ5p try { Meteor.call("addArticle",this.bodyParams); } catch (e) { return {code:500,type:e.error,reason:e.reason}; } } });

the method:

new ValidatedMethod({ name: 'addArticle', .... if (!this.userId) { throw new Meteor.Error(...); //is thrown }

What am I doing wrong?

Answer1:

In Meteor methods you get the current userId by doing

Meteor.userId()

and not

this.userId

So you would need to update your code to

if(!Meteor.userId()){ throw new Meteor.Error(403, '403:Forbidden', 'You shall not pass!') }

Recommend

  • Deferred in $.when while looping an array
  • So we've got MEF working with MVC4, how about the convention based model?
  • Google OAuth2: Redirect has been blocked by CORS policy: Request requires preflight, which is disall
  • Is it possible to password protect an SQL server database?
  • Getting error 'Cannot read property 'document' of undefined' while importing exp
  • PLSQL: Get number of records updated vs inserted when a merge statement is used
  • GAE: Way to get reference to an HttpSession from its ID?
  • How do I configure context broker accept post requests from my remote sensor?
  • saving file generated by TCPDF
  • Eloquent update method change created_at timestamp
  • Display images in Django
  • How to attach a node.js readable stream to a Sendgrid email?
  • Get data from AJAX - How to
  • FB SDK and cURL: Unknown SSL protocol error in connection to graph.facebook.com:443
  • Accessing IRQ description array within a module and displaying action names
  • Is there a amazon webstore API for customers?
  • How to get a value (ex: baseURL) in every Karate feature?
  • Javascript Callbacks with Object constructor
  • Perl system calls when running as another user using sudo
  • Where to put my custom functions in Wordpress?
  • Can a Chrome extension content script make an jQuery AJAX request for an html file that is itself a
  • How to limit post in wp_query
  • Hazelcast - OperationTimeoutException
  • Upload files with Ajax and Jquery
  • How to pass list parameters for each object using Spring MVC?
  • RestKit - RKRequestDelegate does not exist
  • Revoking OAuth Access Token Results in 404 Not Found
  • AngularJs get employee from factory
  • Proper way to use connect-multiparty with express.js?
  • Free memory of cv::Mat loaded using FileStorage API
  • Memory offsets in inline assembly
  • Turn off referential integrity in Derby? is it possible?
  • sending mail using smtp is too slow
  • Busy indicator not showing up in wpf window [duplicate]
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • Binding checkboxes to object values in AngularJs
  • How can I use `wmic` in a Windows PE script?
  • Net Present Value in Excel for Grouped Recurring CF
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?