gpt4 book ai didi

authentication - react 路由器 : Handling role authentication

转载 作者:行者123 更新时间:2023-12-03 14:21:09 27 4
gpt4 key购买 nike

我正在开发一个具有多个角色的网络应用程序。我想到了一种方法,可以使用 React Router 通过 onEnter 触发器来限制对某些路由的访问。

现在我想知道这是否是防止访问未经授权的页面的可靠方法。基本上,破解这个有多容易?只是它不应该太容易被黑客攻击,仅此而已。

请记住,所有正在加载的资源仍然存在服务器端身份验证,因此即使用户确实突破了 React Router,也不会返回未经授权的数据。

  <Route path="/" component={App}>
<IndexRoute onEnter={authenticateUser} />
<Route path="login" component={LoginPage} />
<Route path={roles.ADMIN.homeRoute} component={Admin} onEnter={authenticateAdmin}>
<IndexRoute component={DashboardPage} />
</Route>
<Route path={roles.OPERATIONS.homeRoute} component={Operations} onEnter={authenticateOperations}>
<IndexRoute component={DashboardPage} />
</Route>
</Route>

目前角色路由仅填充有仪表板,但想法是每个角色路由将包含多个子路由。通过此配置,我希望在输入受限角色路由时能够验证用户的角色,但随后能够在子路由之间导航,而无需在每次路由更改时进行身份验证。

最佳答案

这就像修改缓存角色的状态一样简单。只要您对每个资源都有服务器端身份验证,这就不是问题。如果有的话,他们可能能够看到组件的布局,但看不到数据。

关于authentication - react 路由器 : Handling role authentication,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39883286/

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