multica/docs/auth/desktop-integration.md
Naiyuan Qing 31c8b1babc refactor(web): replace devd proxy with Next.js rewrites
- Add rewrites in next.config.ts to proxy /api/* to api-dev.copilothub.ai
- Update docs to reflect new local dev workflow (no devd needed)
- Fix web port number in CLAUDE.md (3001 → 3000)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-13 13:25:08 +08:00

75 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Desktop 登录集成
## 登录流程
```
Desktop 点击登录
启动本地 HTTP 服务器 (随机端口,如 54321)
打开浏览器 → http://localhost:3000/api/desktop/session?port=54321&platform=web
Web 重定向 → /login?next=...
用户登录,调用 /api/v1/auth/login (代理到 api-dev.copilothub.ai)
登录成功,回调 → http://127.0.0.1:54321/callback?sid=xxx&user=xxx
Desktop 保存到 ~/.super-multica/auth.json
```
## 前端逻辑
### Web 端
- 端口:**3000**
- 登录 API`/api/v1/auth/login`(通过 Next.js rewrites 代理到后端)
- 登录成功后回调:`http://127.0.0.1:{port}/callback?sid=xxx&user=xxx`
### Desktop 端
- 点击登录 → 启动本地服务器 → 打开浏览器
- 收到回调 → 保存到本地文件
## 存储
**路径:** `~/.super-multica/auth.json`
Desktop 登录成功后SID 和用户信息存储在本地文件:
```json
{
"sid": "session-id-from-backend",
"user": {
"uid": "user-id",
"name": "User Name",
"email": "user@example.com"
}
}
```
后续请求可从此文件读取 `sid` 进行认证。
## 退出登录
**后端只需要返回错误,前端会自动处理退出。**
前端收到认证错误后:
1. 调用 `auth:clear` 清除本地数据
2. 跳转到登录页
## 本地调试
```bash
# 1. 启动 WebNext.js rewrites 自动代理 /api/* 到 api-dev.copilothub.ai
pnpm dev:web
# 2. 启动 Desktop
pnpm dev:desktop
```
本地调试时Next.js rewrites配置在 `apps/web/next.config.ts`)自动将 `/api/*` 请求代理到 `api-dev.copilothub.ai`
## 参考
- **Cap** - https://github.com/CapSoftware/Cap