自定义用户字段

用户自定义 Metadata 是除了 Authing 基础用户字段之外,开发者可以给用户添加的额外字段,属于 Authing 扩展能力的一部分。

初始化

使用以下接口时,请先完成初始化工作,请参考:

pageSDK for Node.js

你可以在 Authing Pipeline 函数中添加用户 Metadata。

获取用户 Metadata

Authing.metadata(_id)

  • 参数

    • _id <string> 用户 ID,必填。

  • 使用方法

const metadata = await authing.metadata(_id)
  • 返回数据

    • totalCount Metadata 列表长度

    • list

{
  list: [
    {
      key: 'KEY',
      value: 'VALUE',
    },
  ],
  totalCount: 1,
}

添加 Metadata

Authing.setMetadata(input)

  • 参数

    • input <object>

      • _id: <string> 用户 ID,必填。

      • key: <string> 必填。

      • value: <string> 必填。

  • 使用方法

const metadata = await authing.setMetadata({
    _id: user._id,
    key: "KEY",
    value: "VALUE"
})
  • 返回数据

{
  list: [
    {
      key: 'KEY',
      value: 'VALUE',
    },
  ],
  totalCount: 1,
}

删除 Metadata

Authing.removeMetadata(input)

  • 参数

    • input

      • _id: <string> 用户 ID,必填。

      • key: <string> 必填。

  • 使用方法

const metadata = await authing.removeMetadata({
    _id: user._id,
    key: "KEY"
})
  • 返回数据

{
  list: [
    {
      key: 'KEY',
      value: 'VALUE',
    },
  ],
  totalCount: 1,
}

Last updated