
Research
2025 Report: Destructive Malware in Open Source Packages
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.
@antdp/authorized
Advanced tools
权限判断组件或方法,通过判断是否进入主界面还是登录界面。
$ npm i @antdp/authorized # yarn add @antdp/authorized
配置开启。同时需要 config/config.ts 提供权限配置。
import config from '@antdp/config';
import proxy from './proxy';
import router from './router.json';
export default config(router, {
proxy,
define: {
+ ANTD_AUTH_CONF: {
+ auth_menu: 'authMenu',
+ auth_btn: 'authBtn',
+ auth_check_url: true,
}
});
ANTD_AUTH_CONF 权限配置参数| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| auth_menu | 储存菜单路由权限---本地keys | string | authMenu |
| auth_btn | 储存按钮路径权限---本地keys | string | authBtn |
| auth_check_url | 判断路径是否有权限的字段 默认值menuUrl,如果字段设置为undefined则auth_menu和auth_btn储存形式为 ["/web"],反之储存形式为[{menuUrl:"/web"}] | string | menuUrl |
这是你的路由菜单(config/router.json)
[
{
"path": "/login",
"component": "@/layouts/UserLayout"
},
{
"path": "/",
"component": "@/layouts/BasicLayout",
"routes": [
{
"path": "/",
"redirectTo": "/welcome"
},
{
"path": "/welcome",
"name": "首页",
"icon": "welcome",
"locale": "welcome",
"component": "@/pages/Home/index"
},
{
"path": "/404",
"name": "404",
"hideInMenu": true,
"icon": "file-protect",
"component": "@/pages/404"
},
{
"path": "/403",
"name": "403",
"hideInMenu": true,
"icon": "file-protect",
"component": "@/pages/403"
}
]
}
]
登陆后后端返回的菜单列表可能如下
const menus = ['/', '/welcome', '/404', '/403'];
ANTD_AUTH_CONF中配的auth_menu字段,并在登陆后存储在sessionStorage中,如sessionStorage.setItem('authMenu', JSON.stringify([]))authMenu进行权限匹配,如果没有权限则会跳往404或403页面请保证403 和 404页面存在
如果你想根据 token判断是否重定向回登陆页,可在 layouts/BasicLayout.ts 中添加Authorized
import Authorized from '@antdp/authorized';
import BasicLayouts from '@antdp/basic-layouts';
const Layout = () => {
const token =''
return (
<Authorized authority={!!token} redirectPath="/login">
<BasicLayouts
projectName="Ant Design"
/>
</Authorized>
);
};
export default Layout;
很多大型项目中,也会对按钮权限进行管理,请提前配置好ANTD_AUTH_CONF中配的auth_btn字段,并在登陆后存储在sessionStorage中,如sessionStorage.setItem("authBtn",JSON.stringify(['/api/select']))
// 为了渲染设置的本地权限数
import React from "react"
import { AuthorizedBtn } from "@antdp/authorized"
const Demo = ()=>{
return (
<AuthorizedBtn path="/api/select" >
<button>按钮</button>
</AuthorizedBtn>
)
}
export default Demo;
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| path | 权限路径 | string | - |
| children | 展示内容 | React.ReactNode | - |
使用 AuthorizedConfigProvider可以自己进行重新设置组件包裹内的所有按钮的权限参数,不使用默认配置的按钮权限配置
import React from "react"
import { AuthorizedBtn ,AuthorizedConfigProvider } from "@antdp/authorized"
const Page = ()=>{
useEffect(()=>{
sessionStorage.setItem("btn",JSON.stringify([{ menuUrl:"/api/select"} ]))
},[])
return (
<AuthorizedConfigProvider isCheckAuth={true} auth_btn="btn">
<AuthorizedBtn path="/api/select" >
<button>查询</button>
</AuthorizedBtn>
</AuthorizedConfigProvider>
)
}
export default Page
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| auth_menu | 储存菜单路由权限---本地keys | string | authMenu |
| auth_btn | 储存按钮路径权限---本地keys | string | authBtn |
| auth_check_url | 判断路径是否有权限的字段 默认值menuUrl,如果字段设置为undefined则auth_menu和auth_btn储存形式为 ["/web"],反之储存形式为[{menuUrl:"/web"}] | string | menuUrl |
| isCheckAuth | 是否检查权限 | boolean | false |
| children | 子内容 | string | - |
Licensed under the MIT License.
FAQs
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.

Research
/Security News
A five-month operation turned 27 npm packages into durable hosting for browser-run lures that mimic document-sharing portals and Microsoft sign-in, targeting 25 organizations across manufacturing, industrial automation, plastics, and healthcare for credential theft.