认证
获取当前用户
返回当前已认证的用户信息。
响应:
{
"id": "uuid",
"username": "alice",
"displayName": "Alice",
"avatarUrl": "https://...",
"isBot": false
}
const me = await client.getMe()
更新个人资料
| 字段 | 类型 | 说明 |
|---|
displayName | string | 显示名称 |
avatarUrl | string | null | 头像 URL |
const updated = await client.updateProfile({
displayName: 'New Name',
avatarUrl: 'https://example.com/avatar.png',
})
updated = client.update_profile(
display_name="New Name",
avatar_url="https://example.com/avatar.png",
)
获取用户资料
通过 ID 获取公开的用户资料。
const profile = await client.getUserProfile('user-id')
profile = client.get_user_profile("user-id")
注册
无需认证。
| 字段 | 类型 | 必填 | 说明 |
|---|
email | string | 是 | 邮箱地址 |
password | string | 是 | 密码 |
username | string | 否 | 唯一用户名,未填写时自动生成 |
displayName | string | 否 | 显示名称 |
inviteCode | string | 否 | 可选会员邀请码,用于解锁 Cloud 和创建服务器等能力 |
const { accessToken, refreshToken, user } = await client.register({
email: '[email protected]',
password: 'secure-password',
displayName: 'Alice',
})
result = client.register(
email="[email protected]",
password="secure-password",
display_name="Alice",
)
access_token = result["accessToken"]
邮箱验证码登录
POST /api/auth/email/start
POST /api/auth/email/verify
邮箱验证码会登录已有用户,或创建一个普通游客账号。
await client.startEmailLogin({ email: '[email protected]' })
const { accessToken, refreshToken, user } = await client.verifyEmailLogin({
email: '[email protected]',
code: '123456',
})
登录
无需认证。
| 字段 | 类型 | 必填 |
|---|
email | string | 是 |
password | string | 是 |
const { accessToken, refreshToken, user } = await client.login({
email: '[email protected]',
password: 'secret',
})
刷新令牌
返回新的访问令牌和刷新令牌。
const tokens = await client.refreshToken(refreshToken)
result = client.refresh_token(refresh_token)
会员能力
注册不再需要邀请码。邀请码通过会员 API 兑换,用于解锁高阶能力:
GET /api/membership/me
POST /api/membership/redeem-invite
会员响应包含 status、tier、level、isMember 和最终生效的 capabilities。
高阶操作应以 capabilities 为准;后续新增更多等级时无需改变这个响应结构。
常见高阶能力包括 cloud:deploy、server:create、invite:create 和 oauth_app:create。
缺少能力时应展示升级或兑换邀请码路径,而不是把它当成登录失败。
快速认证接口有频控保护。429 响应会包含 RATE_LIMITED 和 Retry-After。
断开连接
POST /api/auth/disconnect
通知服务器客户端正在断开连接(用于在线状态跟踪)。
await client.disconnect()