Meteor-Community-Packages / meteor-roles

Authorization package for Meteor, compatible with built-in accounts packages
http://meteor-community-packages.github.io/meteor-roles/
MIT License
921 stars 166 forks source link

Meteor.user() does not return roles #278

Closed chrux closed 5 years ago

chrux commented 5 years ago

Hey, I am using alanning:roles@1.2.15, for some reason when I entered directly to the page where I validate if a roles is assigned to a user, the user's role attr is not defined/does not exist, any info about what I am doing wrong? It works if I got to other page where I do not have the role validation and after that navigate, but it does not work if I put the url directly or refresh.

Best

alanning commented 5 years ago

Hi @chrux, the roles data hasn't loaded on the client when the check is performed. The roles package will automatically subscribe to get the roles data for the current user but in this case you should have your page template or React view wait on the data before making auth decisions. The publication you need to wait on is named '_roles'.

With Blaze, you can template.subscribe('_roles') in onCreated and then use the template.subscriptionsReady() reactive function to check. See here for more: http://blazejs.org/api/templates.html#Blaze-TemplateInstance-subscribe

chrux commented 5 years ago

Thanks will take a look on that