简体   繁体   English

具有角度和节点的基于角色的页面视图

[英]role-based page views with angular and node

In my app, I have a main page for admins, who should be able to perform admin actions. 在我的应用程序中,我有一个管理员主页,该管理员应该能够执行管理员操作。

I know that all server calls need to be properly authenticated and all that. 我知道所有服务器调用都需要正确地进行身份验证。 Nevertheless I'd like to reduce security problems on the client side as much as possible. 不过,我想尽可能减少客户端的安全问题。 Finally, it's just javascript on the client. 最后,它只是客户端上的javascript。

So how do I design different views role-based on the client? 那么,如何基于客户端角色设计不同的视图? For example, is it a good idea to have different angular base templates for the app as an admin and as a regular user? 例如,以管理员和普通用户的身份为应用提供不同的角度基础模板是个好主意吗? I feel nervous sharing the same template, and then doing things like "if user.role==admin" on the client... 分享同一模板,然后在客户端上执行“ if user.role == admin”之类的事情时,我感到非常紧张。

What is a good approach: I am using passport. 什么是好方法:我正在使用护照。

passport_options =
  successRedirect: '/dashboard'
  failureRedirect: '/'
  failureFlash: true

but this seems not to allow conditional statements (eg successRedirect: if user.role="admin"....) 但这似乎不允许条件语句(例如,successRedirect:if user.role =“ admin” ....)

您可以使用三元运算(?:) ,这种做法在某些情况下会产生不良影响

successRedirect: user.role == 'admin' ? '/dashboad' : '/notAdmin'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM