Docs
文档目录

账号资料、会话与偏好

这是什么 / 何时用

已登录用户对自己账号的读写面:资料(姓名、邮箱、手机号)、密码、偏好(preferences)、登录日志、推送目标(push target)、身份关联(identities),以及 2.6.0 新增的账号级最近 30 天用量聚合。适合做「个人中心」「账号设置」「设备/会话管理」页面。

前置

使用骨架

  1. 读取当前账号:account.get();未登录抛 401,前端据此走登录流程。

  2. 修改资料:updateName / updateEmail(视场景要求 password) / updatePhone / updatePassword(需旧凭据校验)。

  3. 偏好:account.getPrefs() 读取、account.updatePrefs() 合并写入任意 JSON 键值(前端展示偏好、语言等);业务鉴权字段不要放 preferences。

  4. 会话管理:account.listSessions 列出全部活跃会话(含当前),account.getSession 查单条,account.updateSession 刷新指定会话,account.deleteSessions 全部登出、account.deleteSession('current') 登出当前。

  5. 登录日志:account.listLogs 审计登录与敏感操作。

  6. 推送目标:createPushTarget / updatePushTarget / deletePushTarget 维护消息推送目的地(配合 Messaging 使用)。

  7. 身份关联:account.listIdentities 查看已绑定的 OAuth/外部身份,account.deleteIdentity 解绑。

  8. 邮箱/手机验证:account.createEmailVerification(url) → 邮件确认回调调 account.updateEmailVerification({ userId, secret });Phone 对应 createPhoneVerification / updatePhoneVerification。

  9. 密码找回:account.createRecovery(url) → account.updateRecovery({ userId, secret, password })。

  10. 账号用量(2.6.0):account.getUsageAggregates() 返回当前账号最近 30 个 UTC 日的四类标准 Meter 聚合(storage_bytes、bandwidth_bytes、function_executions、users_total),每个 Meter-Day 带 quantity/complete/freshnessAt/reason;quantity: null 表示缺失,不得当 0 展示。

关键参数与返回

调用关键参数返回
get / updateNamename(可选)Models.User($id、email、name、labels、prefs 等)
updateEmail / updatePhoneemail|phone、password(可选)User(匿名转正时 password 即新密码)
updatePasswordnewPassword、oldPassword(可选)User
updatePrefs任意键值对象(合并语义)User
listSessions / getSession / updateSession / deleteSession(s)sessionId(当前会话用 'current')Session 列表 / Session
listLogsqueries(可选;分页/过滤)日志列表
createPushTarget 等targetId、providerId、identifierPushTarget
getUsageAggregates(2.6.0)无(固定最近 30 个 UTC 日,range: '30d')MeterUsageList(四 Meter、coverage、freshness)

错误与边界

SDK 类别差异

各语言调用示例

以下按使用骨架逐项给出各语言调用示例;每个卡片可切换语言(全页同步)。

资料与偏好

本页主体是用户 Session 自助面:Java / Python / Go 经用户态 client 装载 Session 后同构调用同名 Account 方法;REST 回放登录下发的 Session Cookie。

const me = await account.get();   // 未登录抛 401,按未登录处理跳登录
await account.updateName({ name: '新昵称' });
await account.updatePassword({ newPassword: '<new-password>', oldPassword: '<old-password>' });
await account.updatePrefs({ theme: 'dark', lang: 'zh-CN' });   // 合并写入;清键显式置 null
const prefs = await account.getPrefs();

会话管理

sessionId 当前会话用 'current';REST 回放 Session Cookie。

const sessions = await account.listSessions();   // 全部活跃会话(含当前)
await account.updateSession('current');          // 刷新指定会话
await account.deleteSession('current');          // 只登出当前设备
await account.deleteSessions();                  // 连当前会话一起注销

登录日志

listLogs 审计登录与敏感操作;REST 端点未列入 API 参考,走 SDK。

const logs = await account.listLogs();   // queries 可分页/过滤

推送目标

createPushTarget / updatePushTarget / deletePushTarget 维护消息推送目的地(配合 Messaging 使用);REST 端点未列入 API 参考,走 SDK。

await account.createPushTarget({ targetId: ID.unique(), providerId: '<providerId>', identifier: '<device-token>' });
await account.updatePushTarget({ targetId: '<targetId>', identifier: '<device-token>' });
await account.deletePushTarget({ targetId: '<targetId>' });

身份关联

listIdentities 查看已绑定的 OAuth/外部身份,deleteIdentity 解绑;解绑最后一个身份前确认仍有可用登录方式。REST 端点未列入 API 参考,走 SDK。

const identities = await account.listIdentities();
await account.deleteIdentity({ identityId: '<identityId>' });

验证与密码找回

邮箱/手机验证与密码找回都是「发起 → 邮件/短信回调页凭 userId + secret 确认」两步;REST 端点未列入 API 参考,走 SDK。

// 邮箱验证;手机对应 createPhoneVerification / updatePhoneVerification
await account.createEmailVerification('https://example.com/verify');
await account.updateEmailVerification({ userId: '<userId>', secret: '<secret>' });

// 密码找回:回调页直接设置新密码
await account.createRecovery('https://example.com/recovery');
await account.updateRecovery({ userId: '<userId>', secret: '<secret>', password: '<new-password>' });

账号用量(2.6.0)

getUsageAggregates 返回当前账号最近 30 个 UTC 日的四类标准 Meter 聚合;时间窗固定、不可自选区间。REST 端点未列入 API 参考,走 SDK。

const usage = await account.getUsageAggregates();   // quantity: null 表示缺失,不得当 0 展示

示例指引