# updateProfile()

Canonical URL: https://developers.iagenify.com/zh/sdk/ref/auth/update-profile/
Language: zh

`api.auth.updateProfile(updates) → Promise<{ ok, user }>`

更改账户可写性配置字段。只触动您发送的字段。

Status: PUT /api/auth/profile · free · partial update

## 参数 {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `nom` | string |  | 姓 姓 姓 姓 姓 姓 姓 姓 姓 |
| `prenom` | string |  | 名声 |
| `genre` | string |  | 账户上公布 |
| `tel` | string |  | 电话号码 |
| `adresse` | string |  | 街口地址 街口 街口 街口 |
| `ville` | string |  | 城市 |

六个字段, 其它东西都无法在此写入。 电子邮件、 密码和平衡不公开 SDK 业务。

## 部分更新 {#partial}

发送一个字段和一个字段的更改。 不需要先读取配置文件, 也不必写回其它文件的残本 。

```javascript
await api.auth.updateProfile({ ville: "Tunis" });
// everything else is exactly as it was
```

## 空值被降低, 不应用 {#empty}

应用前更新时从空抵达的字段中删除。所以发送 `""` 并不清晰一个领域——它没有改变任何东西,呼吁仍然答案 `ok`。无法通过这种方法将配置字段空白。

```javascript
await api.auth.updateProfile({ ville: "" });
// { ok: true, … } — and "ville" is unchanged

await api.auth.updateProfile({ tel: null });
// the same: nothing is cleared
```

> **提交空白的表格不会按表格上所写的那样**
>
> 未保存的输入会张贴空字符串, 此处忽略空字符串。 只发送用户实际编辑过的字段, 否则页面会报告一个没有发生的更改 。

```javascript
// Build the patch from what changed, not from the whole form
const patch = {};
for (const [field, value] of Object.entries(form)) {
  if (value !== "" && value !== original[field]) patch[field] = value;
}

if (Object.keys(patch).length) await api.auth.updateProfile(patch);
```

## 账户设置中的密码更改 {#password}

A 音 A API 键可以更新配置配置元数据, 因此它永远不能替换账户的证书。 传递 `password` 被本地端的 SDK 和《公约》 API 与 `password_change_private`。使用签名账户设置代替。

## 返回值 {#returns}

服务器现在的账户, 由服务器的账户持有, 密码被解开。 这是完整记录, 比四个字段宽 [$User ()](/zh/sdk/ref/iagenify/get-user) 将其缩小到——阅读它以确认已实现的变更,而不是作为依赖的合同。

```javascript
const { ok, user } = await api.auth.updateProfile({ ville: "Tunis" });

ok;            // true
user.ville;    // "Tunis" — confirmation
// Everything else on `user` is the account record. Treat it as informational.
```

## 错误 {#errors}

| 代码 | 状态 | 触发条件 |
| --- | --- | --- |
| 未经授权 | 401 | 调用时没有有效的会话或密钥 。 |
| password_change_private | 403 | 要求通过公众更改密码 SDK. |
| user_not_found | 404 | 届会将点指向一个不再存在的账户。 |

## 一件值得首先考虑的事 {#privacy}

这些是个人细节,它们是账户持有人的。 写他们的程序应该是因为有人要求这样做,他们给的有价值——而不是因为碰巧有它们就从其他地方抄过来。

- [getUser()](/zh/sdk/ref/iagenify/get-user): 程序通常想要的四块字段
- [api.keys](/zh/sdk/ref/keys): 审计和撤销方案证书,独立于账户设置。

```python
api.auth.update_profile({"ville": "Tunis"})
# everything else is exactly as it was
```

```python
api.auth.update_profile({"ville": ""})
# {"ok": True, ...} — and "ville" is unchanged

api.auth.update_profile({"tel": None})
# the same: nothing is cleared
```

```python
# Build the patch from what changed, not from the whole form
patch = {field: value for field, value in form.items()
         if value != "" and value != original.get(field)}

if patch:
    api.auth.update_profile(patch)
```

```python
answer = api.auth.update_profile({"ville": "Tunis"})

answer["ok"]              # True
answer["user"]["ville"]   # "Tunis" — confirmation
# Everything else on "user" is the account record. Treat it as informational.
```
