{"_id":"@55387.ai/uniauth-react","_rev":"5-e0443603d132aa34ab63626b229e90fe","name":"@55387.ai/uniauth-react","dist-tags":{"latest":"2.0.0"},"versions":{"1.0.0":{"name":"@55387.ai/uniauth-react","version":"1.0.0","keywords":["auth","authentication","react","uniauth","sso","login","hooks"],"_id":"@55387.ai/uniauth-react@1.0.0","maintainers":[{"name":"rosslin","email":"atai829525@gmail.com"}],"dist":{"shasum":"75471c2da9133ad0af007c94d1c3e843b125b300","tarball":"https://registry.npmjs.org/@55387.ai/uniauth-react/-/uniauth-react-1.0.0.tgz","fileCount":6,"integrity":"sha512-vqOubbt636kyJk0RrALNebhL+sHFai68NYdGgEdwYAg+AqGFyfTbJY7/BbPJszc+k1uKAvtBQOFUf4HYc7TFig==","signatures":[{"sig":"MEUCIQCT7SXncer04NnpoSAbBUxA7DPLlBne5+c1gMXPAeXYvwIgV13e0OYyFXhU8Dfbs8Ke+51bdbvES5d9Hvj89byK8B4=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":15398},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.mjs","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"702f1df46a8e121a346601d6bf98ad038374b404","scripts":{"dev":"tsup src/index.ts --format cjs,esm --dts --watch","lint":"eslint src --ext .ts,.tsx","build":"tsup src/index.ts --format cjs,esm --dts --clean","clean":"rm -rf dist"},"_npmUser":{"name":"rosslin","email":"atai829525@gmail.com"},"_npmVersion":"11.8.0","description":"Official React components and hooks for UniAuth integration","directories":{},"_nodeVersion":"25.5.0","dependencies":{"@55387.ai/uniauth-client":"workspace:*"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.3.5","react":"^18.2.0","react-dom":"^18.2.0","typescript":"^5.7.2","@types/react":"^18.2.0","@types/react-dom":"^18.2.0"},"peerDependencies":{"react":">=16.8.0","react-dom":">=16.8.0"},"_npmOperationalInternal":{"tmp":"tmp/uniauth-react_1.0.0_1770697669420_0.9934737216648943","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@55387.ai/uniauth-react","version":"1.0.1","keywords":["auth","authentication","react","uniauth","sso","login","hooks"],"_id":"@55387.ai/uniauth-react@1.0.1","maintainers":[{"name":"rosslin","email":"atai829525@gmail.com"}],"dist":{"shasum":"55096d1b5d43541c6a3a0d171605ca6b1263be72","tarball":"https://registry.npmjs.org/@55387.ai/uniauth-react/-/uniauth-react-1.0.1.tgz","fileCount":6,"integrity":"sha512-YG7yFqN7uEqfasgqf/D3Ua2/+JQAzvoXNjBaWcCTUv0Hmmx9mTapBWz3PyzIXFcNjkXvowdG8IfR+rhbC4PotA==","signatures":[{"sig":"MEUCIQDbXNIg1wd2A3wOpKV+AOGQ00UDLbBy280SmX84p49gggIgT1lInpA2cjo6kzKClaKRSHys1EE3AG3bhdQOAVTr+Vk=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":16327},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.mjs","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"d1df7088f5db2a020f67a20a81dd0b29d775e8ea","scripts":{"dev":"tsup src/index.ts --format cjs,esm --dts --watch","lint":"eslint src --ext .ts,.tsx","build":"tsup src/index.ts --format cjs,esm --dts --clean","clean":"rm -rf dist"},"_npmUser":{"name":"rosslin","email":"atai829525@gmail.com"},"_npmVersion":"11.8.0","description":"Official React components and hooks for UniAuth integration","directories":{},"_nodeVersion":"25.5.0","dependencies":{"@55387.ai/uniauth-client":"workspace:*"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.3.5","react":"^18.2.0","react-dom":"^18.2.0","typescript":"^5.7.2","@types/react":"^18.2.0","@types/react-dom":"^18.2.0"},"peerDependencies":{"react":">=16.8.0","react-dom":">=16.8.0"},"_npmOperationalInternal":{"tmp":"tmp/uniauth-react_1.0.1_1770740972643_0.12225049391182763","host":"s3://npm-registry-packages-npm-production"}},"1.0.2":{"name":"@55387.ai/uniauth-react","version":"1.0.2","keywords":["auth","authentication","react","uniauth","sso","login","hooks"],"_id":"@55387.ai/uniauth-react@1.0.2","maintainers":[{"name":"rosslin","email":"atai829525@gmail.com"}],"dist":{"shasum":"9a87d5c32e341e1c31e3b8d1f19440e91986335d","tarball":"https://registry.npmjs.org/@55387.ai/uniauth-react/-/uniauth-react-1.0.2.tgz","fileCount":6,"integrity":"sha512-waoD1dOESgKL+Q/EpfCLfOhWh2fWxRnOx3z3RAxKcqMpB/PYd6ATArbXYW/e+kZzt++EV2Ia8jebmxZloLgQZA==","signatures":[{"sig":"MEQCIEs+V3ZdLYOy5LNtUGjyShfmZtJFz/75ha8JywwYwoHUAiB63MV/BswEJavB2hXMERRSO/p31tz8g67PsqnQA3G1CA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":16487},"main":"./dist/index.js","type":"module","_from":"file:55387.ai-uniauth-react-1.0.2.tgz","types":"./dist/index.d.ts","module":"./dist/index.mjs","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"scripts":{"dev":"tsup src/index.ts --format cjs,esm --dts --watch","lint":"eslint src --ext .ts,.tsx","build":"tsup src/index.ts --format cjs,esm --dts --clean","clean":"rm -rf dist"},"_npmUser":{"name":"rosslin","email":"atai829525@gmail.com"},"_resolved":"/private/var/folders/4c/_zgqmwls3fdc_qv864lnqcbm0000gn/T/d6627e0631a48aca00f05cdf21f7bdca/55387.ai-uniauth-react-1.0.2.tgz","_integrity":"sha512-waoD1dOESgKL+Q/EpfCLfOhWh2fWxRnOx3z3RAxKcqMpB/PYd6ATArbXYW/e+kZzt++EV2Ia8jebmxZloLgQZA==","_npmVersion":"11.8.0","description":"Official React components and hooks for UniAuth integration","directories":{},"_nodeVersion":"25.5.0","dependencies":{"@55387.ai/uniauth-client":"1.2.4"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.3.5","react":"^18.2.0","react-dom":"^18.2.0","typescript":"^5.7.2","@types/react":"^18.2.0","@types/react-dom":"^18.2.0"},"peerDependencies":{"react":">=16.8.0","react-dom":">=16.8.0"},"_npmOperationalInternal":{"tmp":"tmp/uniauth-react_1.0.2_1770769802702_0.4269856364707496","host":"s3://npm-registry-packages-npm-production"}},"1.0.3":{"name":"@55387.ai/uniauth-react","version":"1.0.3","keywords":["auth","authentication","react","uniauth","sso","login","hooks"],"_id":"@55387.ai/uniauth-react@1.0.3","maintainers":[{"name":"rosslin","email":"atai829525@gmail.com"}],"dist":{"shasum":"3bcbbf996dc0f9ff9d9b794b879c2ddf06b92305","tarball":"https://registry.npmjs.org/@55387.ai/uniauth-react/-/uniauth-react-1.0.3.tgz","fileCount":7,"integrity":"sha512-wQ6AvMAtuu07qDpKbHQtQjZgx2A0fcLkrYv6oYJcuQMAIHFTZLdxEtj4NyzMB42gOPffpYI8eX7hkg907hcSDg==","signatures":[{"sig":"MEYCIQDatuIPQowlC3IzNpr+SjaTcKLtQiBowxxGn9glImGBWwIhAMT8ACzMjMlo4IRVNIOnae+MOWqcsH0E0DR5ZgnZRnKb","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":24250},"main":"./dist/index.js","type":"module","types":"./dist/index.d.ts","module":"./dist/index.mjs","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"9122e48985c5413826715462e3ef89140d044a93","scripts":{"dev":"tsup src/index.ts --format cjs,esm --dts --watch","lint":"eslint src --ext .ts,.tsx","test":"vitest run","build":"tsup src/index.ts --format cjs,esm --dts --clean","clean":"rm -rf dist","test:watch":"vitest"},"_npmUser":{"name":"rosslin","email":"atai829525@gmail.com"},"_npmVersion":"11.8.0","description":"Official React components and hooks for UniAuth integration","directories":{},"_nodeVersion":"25.5.0","dependencies":{"@55387.ai/uniauth-client":"workspace:*"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.3.5","jsdom":"^27.3.0","react":"^18.2.0","vitest":"^4.0.18","react-dom":"^18.2.0","typescript":"^5.7.2","@types/react":"^18.2.0","@types/react-dom":"^18.2.0","@testing-library/react":"^16.3.1","@testing-library/jest-dom":"^6.9.1"},"peerDependencies":{"react":">=16.8.0","react-dom":">=16.8.0"},"_npmOperationalInternal":{"tmp":"tmp/uniauth-react_1.0.3_1770856776521_0.8010307792237139","host":"s3://npm-registry-packages-npm-production"}},"2.0.0":{"name":"@55387.ai/uniauth-react","version":"2.0.0","description":"Official React components and hooks for UniAuth integration","type":"module","main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"publishConfig":{"access":"public"},"scripts":{"build":"tsup src/index.ts --format cjs,esm --dts --clean","dev":"tsup src/index.ts --format cjs,esm --dts --watch","lint":"eslint src --ext .ts,.tsx","clean":"rm -rf dist","test":"vitest run","test:watch":"vitest"},"peerDependencies":{"react":">=16.8.0","react-dom":">=16.8.0"},"dependencies":{"@55387.ai/uniauth-client":"^1.2.5"},"devDependencies":{"@testing-library/jest-dom":"^6.9.1","@testing-library/react":"^16.3.1","@types/react":"^18.2.0","@types/react-dom":"^18.2.0","jsdom":"^27.3.0","react":"^18.2.0","react-dom":"^18.2.0","tsup":"^8.3.5","typescript":"^5.7.2","vitest":"^4.0.18"},"keywords":["auth","authentication","react","uniauth","sso","login","hooks"],"gitHead":"06ef2f089adfb0697adf8003fd39e4b1854efcbb","_id":"@55387.ai/uniauth-react@2.0.0","_nodeVersion":"25.8.0","_npmVersion":"11.11.0","dist":{"integrity":"sha512-+mh6Yv0mwhASIPF9FKhQP5nMEtZll8wMogmVGreBYHwkwDdrjHMgfobbKIqPndHrtGIkyn6+hdsUyK7M93dQKA==","shasum":"e012bbb470e82092d178744ce89084338fd89239","tarball":"https://registry.npmjs.org/@55387.ai/uniauth-react/-/uniauth-react-2.0.0.tgz","fileCount":7,"unpackedSize":24245,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCICil+hauOijrRUViOqeM/tVef93HHSeYjdMrvKpgUu8NAiAwNUUYftDbVr07mgp1src48QZmWgV33Xh122MgLmCbkA=="}]},"_npmUser":{"name":"rosslin","email":"atai829525@gmail.com"},"directories":{},"maintainers":[{"name":"rosslin","email":"atai829525@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/uniauth-react_2.0.0_1773324170269_0.8195357771387282"},"_hasShrinkwrap":false}},"time":{"created":"2026-02-10T04:27:49.359Z","modified":"2026-03-12T14:02:50.573Z","1.0.0":"2026-02-10T04:27:49.560Z","1.0.1":"2026-02-10T16:29:32.792Z","1.0.2":"2026-02-11T00:30:02.861Z","1.0.3":"2026-02-12T00:39:36.657Z","2.0.0":"2026-03-12T14:02:50.421Z"},"keywords":["auth","authentication","react","uniauth","sso","login","hooks"],"description":"Official React components and hooks for UniAuth integration","maintainers":[{"name":"rosslin","email":"atai829525@gmail.com"}],"readme":"# @55387.ai/uniauth-react\n\nOfficial React SDK for UniAuth SSO integration.\nUniAuth 官方 React SDK，用于 SSO 集成。\n\n## Features / 功能\n\n- 🔐 **SSO Integration / SSO 集成**: PKCE authorization code flow with auto-callback handling / 自动处理 PKCE 授权码流程\n- 🔄 **Reactive State / 响应式状态**: `user`, `isAuthenticated`, `isLoading` hooks\n- 🛡️ **TypeScript**: Full type-safe API / 完整类型安全\n- 🍪 **Token Management / Token 管理**: Auto token storage & refresh / 自动存储与刷新\n\n## Installation / 安装\n\n```bash\nnpm install @55387.ai/uniauth-react @55387.ai/uniauth-client\n```\n\n## Quick Start / 快速开始\n\n### 1. Configure Provider / 配置 Provider\n\n```tsx\n// src/main.tsx\nimport React from 'react';\nimport ReactDOM from 'react-dom/client';\nimport { UniAuthProvider, type UniAuthProviderConfig } from '@55387.ai/uniauth-react';\nimport App from './App';\n\nconst config: UniAuthProviderConfig = {\n  baseUrl: import.meta.env.VITE_UNIAUTH_BASE_URL || 'https://sso.55387.xyz',\n  clientId: import.meta.env.VITE_UNIAUTH_CLIENT_ID,\n  redirectUri: window.location.origin + '/callback',\n  sso: {\n    ssoUrl: 'https://sso.55387.xyz',\n    clientId: import.meta.env.VITE_UNIAUTH_CLIENT_ID, // Required / 必填\n    redirectUri: window.location.origin + '/callback', // Required / 必填\n    usePKCE: true,\n  }\n};\n\nReactDOM.createRoot(document.getElementById('root')!).render(\n  <React.StrictMode>\n    <UniAuthProvider config={config} loadingComponent={<div>Loading...</div>}>\n      <App />\n    </UniAuthProvider>\n  </React.StrictMode>\n);\n```\n\n> [!IMPORTANT]\n> The `sso` configuration object is **REQUIRED** if you intend to use the `login()` method from `useUniAuth()`.\n> 如果您打算使用 `useUniAuth()` 中的 `login()` 方法，`sso` 配置对象是 **必须** 的。\n\n### 2. Use the Hook / 使用 Hook\n\n```tsx\nimport { useUniAuth } from '@55387.ai/uniauth-react';\n\nexport const LoginButton = () => {\n  const { user, isAuthenticated, isLoading, login, logout } = useUniAuth();\n\n  if (isLoading) return <div>Checking session...</div>;\n\n  if (isAuthenticated && user) {\n    return (\n      <div>\n        <img src={user.avatar_url} alt={user.nickname} />\n        <span>Welcome, {user.nickname}!</span>\n        <button onClick={() => logout()}>Logout</button>\n      </div>\n    );\n  }\n\n  return <button onClick={() => login()}>Login with SSO</button>;\n};\n```\n\n## API Reference\n\n### `useUniAuth()` Hook\n\nReturns `UniAuthContextType`:\n\n| Property / 属性 | Type / 类型 | Description / 描述 |\n|---|---|---|\n| `user` | `UserInfo \\| null` | Current user info / 当前用户信息 |\n| `isAuthenticated` | `boolean` | Auth status / 认证状态 |\n| `isLoading` | `boolean` | Loading state / 加载状态 |\n| `error` | `Error \\| null` | Error state / 错误状态 |\n| `login(options?)` | `(opts?) => void` | Start SSO login / 发起 SSO 登录 |\n| `logout()` | `() => Promise<void>` | Logout / 退出登录 |\n| `updateProfile(updates)` | `(updates) => Promise<void>` | Update profile (nickname, avatar) / 更新资料 |\n| `client` | `UniAuthClient` | Raw client instance / 原始客户端实例 |\n| `getToken()` | `() => string \\| null` | Get access token synchronously / 同步获取 Token |\n\n### `login()` Options\n\n```ts\nlogin({ usePKCE: true, usePopup: false });\n```\n\n| Option | Default | Description / 描述 |\n|---|---|---|\n| `usePKCE` | `true` | Use PKCE flow (recommended for SPA) / 使用 PKCE 流程 |\n| `usePopup` | `false` | Open login in popup / 弹窗登录 |\n\n## Advanced Usage / 高级用法\n\n### Getting Access Token / 获取 Access Token\n\n```ts\nconst { getToken } = useUniAuth();\n\nconst callApi = async () => {\n  const token = getToken();\n  if (!token) return;\n\n  const res = await fetch('/api/protected', {\n    headers: { Authorization: `Bearer ${token}` }\n  });\n};\n```\n\n### Update User Profile / 更新用户资料\n\n```ts\nconst { updateProfile } = useUniAuth();\n\nawait updateProfile({ nickname: 'New Name' });\n```\n\n### Access Raw Client / 访问原始客户端\n\n```ts\nconst { client } = useUniAuth();\n\n// Use any UniAuthClient method directly\n// 直接使用 UniAuthClient 的任何方法\nawait client.sendCode('+8613800138000');\nconst result = await client.loginWithCode('+8613800138000', '123456');\n```\n\n## Environment Variables / 环境变量\n\n```bash\nVITE_UNIAUTH_BASE_URL=https://sso.55387.xyz\nVITE_UNIAUTH_CLIENT_ID=your-client-id\n```\n\n## Troubleshooting / 故障排查\n\n### `invalid_client` Error\n- Check `clientId` matches Console exactly / 检查 clientId 是否与控制台完全一致\n- Check `redirectUri` matches Console exactly / 检查 redirectUri 是否与控制台完全一致\n\n### 404 on Callback / 回调 404\n- Ensure React Router handles `/callback` route / 确保路由处理了 `/callback` 路径\n- Configure Nginx: `try_files $uri /index.html`\n\n### CORS Errors / 跨域错误\n- Add your domain to `CORS_ORIGINS` on SSO Server / 在 SSO 服务器添加域名到 CORS_ORIGINS\n- Or configure Nginx proxy: `/api/uni-auth/` → SSO Server / 或配置 Nginx 代理\n\n## 🤖 AI Agent Prompts / AI 智能体提示词\n\nThis package includes an AI-ready integration prompt. Copy it into your AI coding assistant (Claude, Cursor, Copilot, etc.) to generate a complete UniAuth integration automatically.\n\n本包附带 AI 集成提示词。将其复制到 AI 编程助手中，即可自动生成完整的 UniAuth 集成代码。\n\n```bash\n# After install, find the prompt at:\n# 安装后，提示词文件位于：\ncat node_modules/@55387.ai/uniauth-react/ai-prompts/react-nextjs.md\n```\n\n> [!TIP]\n> Replace placeholders like `YOUR_UNIAUTH_URL` and `YOUR_CLIENT_ID` before pasting into your AI assistant.\n> 粘贴到 AI 助手前，请替换 `YOUR_UNIAUTH_URL` 和 `YOUR_CLIENT_ID` 等占位符。\n\nSee all prompts: [docs/ai-prompts/](../../docs/ai-prompts/README.md)\n","readmeFilename":"README.md"}