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
920 stars 167 forks source link

Make auto-subscriptions wait until there is a logged in user #331

Open jankapunkt opened 3 years ago

jankapunkt commented 3 years ago

This kind of a question / feature request.

Currently the package's client code automatically subscribes to the roles and immediately causes data being loaded.

I would like to defer this step until my users are actually logged in reducing the initial data load when starting the app. I know this is just a tiny performance improvement but many of these small things add up in the end.

Proposed solution:

Tracker.autorun(function () {
  if (!Meteor.userId()) return
  Roles.subscription = Meteor.subscribe('_roles')
})

I assume, that the information about user roles on the client makes no sense until there is not a logged in user (correct me if there is a usecase, that contradicts this assumption). Therefore this should not have any negative impact on current setups.

I could provide a PR for this

SimonSimCity commented 3 years ago

I'd say this is a good candidate for the next major version 😎 #295

drone1 commented 1 week ago

Roles.subscription got deleted? I don't see any info about this in the v4 notes. Actually I don't see any v4 notes :) My code waits for Roles.subscription.ready() – please advise! Thank you.