multica/docs/auth/desktop-integration.md
yushen 4dba1cfdf0 refactor: unify API URL env var to MULTICA_API_URL
Replace scattered API_URL, MAIN_VITE_API_URL, and RENDERER_VITE_API_URL
with a single MULTICA_API_URL across all apps and packages.

- Desktop: use envPrefix to expose MULTICA_* to main process, rename
  RENDERER_VITE_API_URL → RENDERER_VITE_MULTICA_API_URL, remove
  MAIN_VITE_API_URL (now read directly via MULTICA_API_URL)
- Web: add .env.development with MULTICA_API_URL, enforce required check
  in next.config.ts, update .gitignore to allow .env.development
- Core: make MULTICA_API_URL required in api-client (no silent fallback)
- Scripts: pass MULTICA_API_URL in dev-local.sh for web process
- Turbo: update globalEnv from API_URL to MULTICA_API_URL
- Docs: update references to the new env var name

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 06:31:00 +08:00

1.7 KiB
Raw Blame History

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 和用户信息存储在本地文件:

{
  "sid": "session-id-from-backend",
  "user": {
    "uid": "user-id",
    "name": "User Name",
    "email": "user@example.com"
  }
}

后续请求可从此文件读取 sid 进行认证。

退出登录

后端只需要返回错误,前端会自动处理退出。

前端收到认证错误后:

  1. 调用 auth:clear 清除本地数据
  2. 跳转到登录页

本地调试

# 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/* 请求代理到 MULTICA_API_URL 指定的后端。

参考