我认为,从安全 Angular ,最好在两个地方处理对受限 URL 的访问:
- 路由级别:确保没有人能够到达不允许的路由
- 模板级别:在验证权限之前不会显示受限数据。
Iron-Router
支持第一种方式,但我想使用Flow-Router
。
我找到了 Satya van He-men
的一篇文章,Meteor: Using Flow Router for authentication and permissions
在本文中,他使用路由组和触发器按权限“过滤”路由。
但是在这篇文章中他使用的是
Meteor.loggingIn()
、Meteor.userId()
、Meteor.user()
和 Roles.userIsInRole()
在 triggersEnter:
对象的 FlowRouter
函数中。
在 triggersEnter
执行期间,这些函数中是否有可能未定义?
使用它们安全吗?
我喜欢文章中的模式,但想确保它可以安全使用(或者可以通过少量更改变得安全)
最佳答案
我认为您的担忧是有道理的,这可能是因为 triggersEnter
只调用了一次我建议阅读有关模板级别的 Auth Logic Permission 的官方教程,它是响应式(Reactive)的。
Previously, we did this in the router layer (specifically with Iron Router). However, that's not a good design and we don't recommend it.
https://kadira.io/academy/meteor-routing-guide/content/implementing-auth-logic-and-permissions
关于javascript - 带有流量路由器的 meteor : Do I have access to Meteor. 来自流量路由器触发器的用户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33462525/