Meteor-Community-Packages/meteor-roles

Question: How to reactively check roles in React with v4.0.0?

開放

#416 建立於 2025年2月3日

 (5 則留言) (0 個反應) (0 位負責人)JavaScript (161 個分叉)batch import
enhancementgood first issue

倉庫指標

星標
 (919 顆星)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

I upgraded from Meteor 2 with roles@1.x to Meteor 3 with roles@4.0.0. With the old package, where the roles were bound to the user object, calls to Roles.isUserInRole() worked reactively. We used this a lot to enable or disable app features based on roles. It was pretty impressive when we just added new features to a user in a Zoom session.

But now, the user has to reload the page to get the upated roles information, although I publish the role information like this:

import { Meteor } from 'meteor/meteor';

Meteor.publish(null, async function() {
 if (!this.userId) return this.ready();
 return Meteor.roleAssignment.find({ 'user._id': this.userId });
});

What is the best way to get back to the old reactivity in React? A hook maybe that works reactively?

貢獻者指南