gpt4 book ai didi

javascript - Roles.userIsInRole 返回 FALSE - Meteor

转载 作者:行者123 更新时间:2023-11-30 11:36:05 24 4
gpt4 key购买 nike

我将 FlowRouterFlowTemplate 一起使用,并且在 both/router/router.js 中我正在检查它是否是 admin Angular 色中的用户:

....
action: function () {
if(Roles.userIsInRole(Meteor.userId(), 'admin')){
FlowLayout.render('layout', {
sidebar: 'sidebar', main:'admin', cart:'cart'
})
} else {
FlowLayout.render('layout', {
sidebar: 'sidebar', main:'unauthorised', cart:'cart'
})
}

console.log(Meteor.userId());

}
....

并返回FALSE,但是当我在WEB控制台中使用它时是TRUE。此行 console.log(Meteor.userId()); 输出正确的 userID 并且当我登录时,如果我在 WEB 控制台中执行此操作 Roles .userIsInRole(Meteor.userId(), 'admin'),它是 TRUE。如果我这样做 Meteor.user().roles,结果是 ['admin']

如果我在模板中检查它是否是 Angular 色中的用户:

{{#if isInRole 'admin' }}
ADMIN
{{/if}}

它是TRUE,但在router.js 中返回FALSE

如何解决?

最佳答案

roles 字段很可能在稍后阶段收到(基于不同的订阅)。

您应该确保此订阅已准备就绪 - 直接或通过使用其他机制来确保您获得该字段(例如确保它是一个数组),然后才做出路由/渲染决定.

关于javascript - Roles.userIsInRole 返回 FALSE - Meteor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44358450/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com