认证

获取当前用户

GET /api/auth/me

返回当前已认证的用户信息。

响应:

{
  "id": "uuid",
  "username": "alice",
  "displayName": "Alice",
  "avatarUrl": "https://...",
  "isBot": false
}
const me = await client.getMe()
me = client.get_me()

更新个人资料

PATCH /api/auth/me
字段类型说明
displayNamestring显示名称
avatarUrlstring | 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",
)

获取用户资料

GET /api/auth/users/:id

通过 ID 获取公开的用户资料。

const profile = await client.getUserProfile('user-id')
profile = client.get_user_profile("user-id")

注册

POST /api/auth/register

无需认证。

字段类型必填说明
emailstring邮箱地址
passwordstring密码
usernamestring唯一用户名,未填写时自动生成
displayNamestring显示名称
inviteCodestring可选会员邀请码,用于解锁 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',
})

登录

POST /api/auth/login

无需认证。

字段类型必填
emailstring
passwordstring
const { accessToken, refreshToken, user } = await client.login({
  email: '[email protected]',
  password: 'secret',
})
result = client.login(email="[email protected]", password="secret")

刷新令牌

POST /api/auth/refresh

返回新的访问令牌和刷新令牌。

const tokens = await client.refreshToken(refreshToken)
result = client.refresh_token(refresh_token)

会员能力

注册不再需要邀请码。邀请码通过会员 API 兑换,用于解锁高阶能力:

GET /api/membership/me POST /api/membership/redeem-invite

会员响应包含 statustierlevelisMember 和最终生效的 capabilities。 高阶操作应以 capabilities 为准;后续新增更多等级时无需改变这个响应结构。

常见高阶能力包括 cloud:deployserver:createinvite:createoauth_app:create。 缺少能力时应展示升级或兑换邀请码路径,而不是把它当成登录失败。

快速认证接口有频控保护。429 响应会包含 RATE_LIMITEDRetry-After


断开连接

POST /api/auth/disconnect

通知服务器客户端正在断开连接(用于在线状态跟踪)。

await client.disconnect()
client.disconnect()