# xhhk-auth-lib
**Repository Path**: starview/xhhk-auth-lib
## Basic Information
- **Project Name**: xhhk-auth-lib
- **Description**: 惠康智汇H5,惠康智汇智能问答H5的共享鉴权库
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2026-05-21
- **Last Updated**: 2026-07-01
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# @xhhk/auth
星华惠康 H5 共享鉴权库,为 React 项目提供统一的登录、权限、路由守卫能力。
## 安装
```bash
npm install @xhhk/auth
```
## 使用
### 1. 入口文件(index.tsx)
```tsx
import { AuthProvider, setupAxiosInterceptor } from '@xhhk/auth';
import { BrowserRouter } from 'react-router-dom';
setupAxiosInterceptor(() => {
window.location.href = '/login';
});
const root = createRoot(document.getElementById('root')!);
root.render(
);
```
### 2. 登录页
```tsx
import { useAuth } from '@xhhk/auth';
const { login } = useAuth();
await login({ username: 'xxx', password: 'xxx' });
```
### 3. 路由守卫
```tsx
import { PermissionGuard } from '@xhhk/auth';
}
/>
```
### 4. 组件内权限判断
```tsx
import { usePermission } from '@xhhk/auth';
const hasPermission = usePermission();
{hasPermission('export-button', 'export') && }
```
### 5. SSO 登录
支持通过 transfer token 免密登录(从微信公众号/企业微信跳转)。