流星用户属性 [英] Meteor User Property

查看:28
本文介绍了流星用户属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在 Meteor 身份验证系统中将用户标记为管理员",并允许该用户做特殊的事情,以及显示一些我不会显示的 gui 元素,如果它们不是行政.我已经尝试在用户对象上设置一个admin"属性,它可以在服务器端正常工作(对于管理操作的 RPC),但是我需要在客户端访问它以更改渲染页面,似乎只有电子邮件与 Meteor.user() 对象一起发送.

I'd like to be able to mark users as "admin" in the Meteor auth system, and allow that user to do special things, as well as show some gui elements I wouldn't show if they weren't an admin. I've already tried setting an "admin" property on the user object, which would work fine on the server side (for the RPCs for the admin actions), however I need to access it on the client side to change the rendering of the page, and it appears only emails is sent with the Meteor.user() object.

基本问题:如何分配服务器和客户端都可以看到的特定于用户的属性?

Basic question: How can I assign a user-specific property that both the server and client can see?

推荐答案

对于将来的任何人,只需在数据库的 users 表中分配值.您可以使用以下方法向用户发布其他字段:

To anyone in the future, simply assign the value in the users table in the database. You can publish additional fields to the user using the following:

Meteor.publish("userData", function () {
     return Meteor.users.find({_id: this.userId}, {fields: {'admin': 1}});
});

在客户端:

Meteor.subscribe("userData");

噗.直接来自文档.

这篇关于流星用户属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆