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

Error: Meteor.userId can only be invoked in method calls. #40

Closed
vhuerta opened this issue Apr 27, 2015 · 2 comments
Closed

Error: Meteor.userId can only be invoked in method calls. #40

vhuerta opened this issue Apr 27, 2015 · 2 comments

Comments

@vhuerta
Copy link

vhuerta commented Apr 27, 2015

Hi, Im getting this error:

Error: Meteor.userId can only be invoked in method calls. Use this.userId in publish functions. at Object.Meteor.userId

Im just create this file (/server/services/rest_services.js):

    Restivus.configure({
        apiPath: 'api/',
        useAuth: true,
        prettyJson: true,
        enableCors: true
    });

    Restivus.addRoute('user/email_change/:email', {authRequired: false}, {
        get: function () {

        }
    });

Why do you think this happens ?

@vhuerta
Copy link
Author

vhuerta commented Apr 27, 2015

ok i found why this was happening, because i have this in my router configuration:

Router.onBeforeAction(function () {
    if (!Meteor.userId()) {
        this.redirect('/login');
    }
    this.next();
});

i changed to

Router.onBeforeAction(function () {
    if (!Meteor.isServer && !Meteor.userId()) {
        this.redirect('/login');
    }
    this.next();
});

and now is working fine

@vhuerta vhuerta closed this as completed Apr 27, 2015
@kahmali
Copy link
Owner

kahmali commented Apr 28, 2015

Thanks for reporting this issue and updating it with the solution! Unfortunately, I don't think #38 will fix this. I'll have to test to see if iron router hooks run before routes that aren't defined with iron router.

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

No branches or pull requests

2 participants