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

Fix for userIsInRole helper: Check to handle when userRoles is null. #168

Merged
merged 2 commits into from
Feb 1, 2016

Conversation

shwaydogg
Copy link
Contributor

Certain race conditions can cause userRoles to be null and an exception to be thrown. Even while wrapping with currentUser helper:

{{#if currentUser}}
{{#if isInRole 'coach'}} ....

typeof(null) returns "object" so the check on the previous line is not enough to avoid a js exception: 'object' === typeof userRoles.

@alanning I'll be at Devshop tomorrow if there's anything to discuss :)

@mitar
Copy link
Member

mitar commented Jan 20, 2016

This is fixed in v2.0 branch with a different check: https://github.com/alanning/meteor-roles/blob/v2.0/roles/roles_common.js#L851

@mitar mitar closed this Jan 20, 2016
@mitar
Copy link
Member

mitar commented Jan 20, 2016

But thanks for reporting. Please do test v2.0 to see if it still does not work for you.

@mitar
Copy link
Member

mitar commented Jan 20, 2016

BTW, I am not sure which race conditions can make roles null? They can make it so that the field does not exist, or that it does. But not that it is null? Is this something specific to your code? Anyway, in v2.0 we have user.roles || [] which will take care of this as well.

@shwaydogg
Copy link
Contributor Author

Thanks for the reply Mitar! Just realized it might end up being null do a transforms not catching up. I'm using the jagi:astronomy and it will set fields to null.

Adrian did mention you were moving to 2.0, but as this is a bugfix and not a feature additions it might still make sense to add in the 1.0 line for those who don't upgrade. Up to you guys of course.

@mitar
Copy link
Member

mitar commented Jan 20, 2016

You are right. Can you then do else if (userRoles && 'object' === typeof userRoles) { instead there?

@mitar mitar reopened this Jan 20, 2016
@mitar
Copy link
Member

mitar commented Feb 1, 2016

Thanks.

mitar added a commit that referenced this pull request Feb 1, 2016
Fix for userIsInRole helper: Check to handle when `userRoles` is null.
@mitar mitar merged commit 3282f07 into Meteor-Community-Packages:master Feb 1, 2016
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

Successfully merging this pull request may close these issues.

2 participants