
Security News
CVE Volume Surges Past 48,000 in 2025 as WordPress Plugin Ecosystem Drives Growth
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.
apps-key-guard
Advanced tools
一个基于密钥验证的 React 访问控制组件,支持本地缓存和自动验证。
npm install @apps-admin/key-guard
或者
yarn add @apps-admin/key-guard
import { KeyGuard } from '@apps-admin/key-guard';
function App() {
return (
<KeyGuard appName="my-app" apiBaseUrl="http://localhost:8080">
<div>
<h1>受保护的内容</h1>
<p>只有通过密钥验证的用户才能看到这里的内容</p>
</div>
</KeyGuard>
);
}
import { KeyGuard } from '@apps-admin/key-guard';
function App() {
const handleValidated = (level: string) => {
console.log('用户验证成功,等级:', level);
// 可以根据等级做不同的处理
};
return (
<KeyGuard
appName="my-app"
apiBaseUrl="https://api.example.com"
title="请输入访问密钥"
placeholder="输入您的密钥"
buttonText="提交验证"
onValidated={handleValidated}
customStyle={{
backgroundColor: '#f0f0f0',
}}
>
<div>
<h1>受保护的内容</h1>
<p>只有通过密钥验证的用户才能看到这里的内容</p>
</div>
</KeyGuard>
);
}
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
appName | string | 是 | - | 应用名称,用于标识应用 |
apiBaseUrl | string | 否 | http://localhost:8080 | API 基础 URL |
children | ReactNode | 是 | - | 验证成功后要渲染的子组件 |
onValidated | (level: Level) => void | 否 | - | 验证成功后的回调函数,返回密钥等级 |
customStyle | CSSProperties | 否 | - | 自定义容器样式 |
title | string | 否 | 访问验证 | 标题文本 |
placeholder | string | 否 | 请输入访问密钥 | 输入框占位符 |
buttonText | string | 否 | 验证 | 按钮文本 |
showFloatingButton | boolean | 否 | true | 是否显示悬浮按钮 |
none 时,渲染子组件验证成功后,页面右下角会显示一个悬浮按钮。点击按钮可以打开信息面板,显示:
安全性:关闭面板时会自动重置密钥显示状态为隐藏,保护用户隐私。
可以通过 showFloatingButton={false} 禁用悬浮窗功能。
组件需要后端提供一个密钥验证接口:
POST /api/public/keys/verify
请求体:
{
"app_name": "my-app",
"key_value": "user-input-key"
}
响应格式:
{
"code": 200,
"message": "验证成功",
"data": {
"valid": true,
"level": "vip",
"expires_at": "2024-12-31T23:59:59Z",
"message": "密钥有效"
}
}
none: 无权限(验证会失败)guest: 游客vip: VIP 用户super_vip: 高级 VIP 用户使用 Vite 开发服务器快速测试组件:
# 安装依赖
npm install
# 启动开发服务器(自动打开浏览器)
npm run dev
开发服务器会在 http://localhost:3000 启动,并提供多个示例供测试:
测试前准备:
http://localhost:8080)# 使用后端 API 创建应用
POST /api/apps
{
"name": "my-app",
"remark": "测试应用"
}
none):
POST /api/keys
{
"app_id": 1,
"key_value": "test-key-123",
"level": "vip"
}
# 构建用于发布的包(监听模式)
npm run build:watch
# 构建用于发布的包
npm run build
# 预览构建结果
npm run preview
MIT
FAQs
A React component for key-based access control with localStorage caching
We found that apps-key-guard demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.

Security News
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.