# `Rivet.Ident.User.Lib.Update`
[🔗](https://github.com/srevenant/rivet-ident/blob/main/lib/ident/user/lib/update.ex#L1)

Making changes to a user (administratively or as the user).

See UsersUpdate.update @spec for details on args.  Explains for said args:

- `user_changes` map is variable, in that it's keys may vary based on the input
  args sent into GraphQL updatePerson() mutation
- `caller_authz` is the level of authorization for the caller, which changes
  what updates are allowed.
- `target_user` is optional, if nil the user should be created, if exists then
  it's an update for that user

Example (create):

  ```elixir
  ==> Rivet.Ident.UsersUpdate.update(%{
      action: :upsert,
      user: %{name: "The Doctor"},
      email: %{email: "who@tardis.com"}
    }, :admin)
  {:ok, %User{}, %{"password": "R^EkW)aBY9G9", "passwordExp": 1649947803}}
  ```
  Rivet.Ident.UsersUpdate.update(%{ action: :upsert, user: %{name: "The Doctor"}, email: %{email: "who@tardis.com"} }, :admin)

  Example — update a user's name as the user

  ```elixir
  ==> Rivet.Ident.UsersUpdate.update(%{
    action: :upsert,
    user: %{name: "Who"},
  }, :user, %User{...})
  {:ok, %User{}, %{}}
  ```

  Example — remove a phone

  ```elixir
  ==> Rivet.Ident.UsersUpdate.update(%{
    action: :remove,
    phone: %{id: "2342343-...-33"},
  }, :user, %User{...})
  {:ok, %User{}, %{}}
  ```

# `preflight_user_create`

# `update`

```elixir
@spec update(
  user_changes :: map(),
  caller_authz :: :admin | :user,
  target_user :: Rivet.Ident.User.t() | nil
) :: {:ok, Rivet.Ident.User.t()} | {:error, reason :: String.t()}
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
