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

Best way to get current User #42

Open
joejeet opened this issue Feb 23, 2016 · 3 comments
Open

Best way to get current User #42

joejeet opened this issue Feb 23, 2016 · 3 comments

Comments

@joejeet
Copy link

joejeet commented Feb 23, 2016

I need to get the info about current user in server side static template. So, I use Meteor.userId() in server side template helper to get current user it works but it throws exception and ask to use this.userId which is undefined in this case.

@smilansky
Copy link

Are you sure there is a logged in user when you call the method that is rendering the template? Console log Meteor.userId() from the browser before trigger the method. this.userId returns the userId of the user that called the method, and if it is returning undefined, then most like the current user isn't set.

Are you using Meteor Accounts?

@joejeet
Copy link
Author

joejeet commented Feb 24, 2016

Thanks for reply.

Updated my answer

I'm using this example explain in this. Rather than for SEO(escaped fragment) only I want posts show page to be render from server.

@CaptainChemist
Copy link

I'm running into this same issue. This is my method and it returns an error, did you ever fix this issue?

export const keys = new ValidatedMethod({
  name: 'get.keys',
  validate: new SimpleSchema({
  }).validator(),
  run({ }) {
    if (Roles.userIsInRole(Meteor.userId(), ['admin'])){
       return 'test';
    } else {
      throw new Meteor.Error(500, 'You are not an admin!');
    }
  },
});

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

3 participants