@qmuse/cloud-client 1.0.2 → 1.0.3-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # @qmuse/cloud-client
2
2
 
3
+ 用户名密码登录请先读 [认证接入契约与完整示例](docs/auth.md):包含输入字段、用户返回值、恢复会话、注册后登录和退出。
4
+ 下方 SDK 示例使用宿主已初始化的客户端;QMuse 生成项目通过 `src/services/cloud` 接入,项目接入说明由 CLI 同步此认证契约。
5
+
3
6
  Unified Web/PC/mini-program client for QMuse Cloud services. Business APIs use
4
7
  the single `qmuse-cloud-api` AppBase Function. File policy uses that Function as
5
8
  its control plane while large file bytes use a platform-specific Storage data
package/docs/auth.md ADDED
@@ -0,0 +1,31 @@
1
+ ## 用户名密码认证
2
+
3
+ `register` / `login` 接收 `{ username: string, password: string }`,输入类型为 `CloudRegisterInput` / `CloudLoginInput`。表单、Hook 和调用对象统一使用 `username`,不是 `email`。
4
+
5
+ 成功返回的 `CloudAuthUser` 是用户对象本身,不需要再取 `.data` 或 `.user`:
6
+
7
+ | 字段 | 类型 | 用途 |
8
+ | --- | --- | --- |
9
+ | `id` | `string` | 应用用户 ID,不是数据库行的 `$id` |
10
+ | `username` | `string` | 用户名;显示名称使用此字段,不假设存在 `name` 或 `email` |
11
+ | `avatarUrl` | `string` | 可直接用于图片的头像 URL |
12
+ | `role` | `'user' \| 'admin'` | 应用角色;业务权限仍由服务端校验 |
13
+
14
+ ```ts
15
+ import { getQMuseClient, type CloudAuthUser, type CloudLoginInput } from '@qmuse/cloud-client';
16
+
17
+ const authService = getQMuseClient().auth;
18
+
19
+ export const restoreUser = (): Promise<CloudAuthUser | null> => authService.restoreSession();
20
+ export const signOut = (): Promise<void> => authService.logout();
21
+ export async function submitAuth(mode: 'login' | 'register', username: string, password: string): Promise<CloudAuthUser> {
22
+ const input: CloudLoginInput = { username, password };
23
+ if (mode === 'register') await authService.register(input);
24
+ return authService.login(input);
25
+ }
26
+ ```
27
+
28
+ - 页面启动先等待 `restoreUser()`;返回用户后才加载私有数据,返回 `null` 时展示登录表单。异常应展示服务错误,不等同于未登录。
29
+ - `register()` 只创建账号,不建立或替换 Session。只有 `submitAuth()` 登录成功后才更新已登录状态、加载私有数据;注册成功而登录失败时,提示账号已创建并引导登录,不自动重新注册。
30
+ - 退出成功后清空页面用户和私有数据缓存;恢复会话为空时同样清空旧状态。
31
+ - 请求失败通过异常返回,私有 API 的 401 按未登录处理;网络错误和 5xx 保留服务异常语义。不记录密码或 Session,不从页面传入角色或用户 ID 代替服务端鉴权。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qmuse/cloud-client",
3
- "version": "1.0.2",
3
+ "version": "1.0.3-dev.0",
4
4
  "description": "Narrow HTTP-style client for the single QMuse Cloud API Function",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -23,6 +23,7 @@
23
23
  },
24
24
  "files": [
25
25
  "dist",
26
+ "docs",
26
27
  "README.md",
27
28
  "LEGAL.md"
28
29
  ],