# `TypeDB.User`
[🔗](https://github.com/NoeticEcho/TypedbEx/blob/v0.11.0/typedb/lib/typedb/user.ex#L1)

User administration.

Most of these endpoints require administrator rights; a non-admin user can
generally read and update only its own record.

    {:ok, usernames} = TypeDB.User.list(conn)
    :ok = TypeDB.User.create(conn, "alice", "s3cret")
    :ok = TypeDB.User.set_password(conn, "alice", "even-more-s3cret")
    :ok = TypeDB.User.delete(conn, "alice")

# `create`

```elixir
@spec create(TypeDB.Connection.t(), String.t(), String.t(), keyword()) ::
  :ok | {:error, TypeDB.Error.t()}
```

Creates a user with the given password.

# `create!`

```elixir
@spec create!(TypeDB.Connection.t(), String.t(), String.t(), keyword()) :: :ok
```

Creates a user, raising on failure.

# `current`

```elixir
@spec current(
  TypeDB.Connection.t(),
  keyword()
) :: {:ok, String.t()} | {:error, TypeDB.Error.t()}
```

Returns the user this connection signed in as.

Rust's `users().get_current()`, and the same implementation: there is no
endpoint for it, so the name comes from the connection's own credentials and
is then looked up — which means it also answers "does the account I am using
still exist".

A connection configured with a pre-issued `:token` has no username to look up,
and says so rather than guessing.

# `current!`

```elixir
@spec current!(
  TypeDB.Connection.t(),
  keyword()
) :: String.t()
```

Returns the user this connection signed in as, raising on failure.

# `delete`

```elixir
@spec delete(TypeDB.Connection.t(), String.t(), keyword()) ::
  :ok | {:error, TypeDB.Error.t()}
```

Deletes a user.

# `delete!`

```elixir
@spec delete!(TypeDB.Connection.t(), String.t(), keyword()) :: :ok
```

Deletes a user, raising on failure.

# `exists?`

```elixir
@spec exists?(TypeDB.Connection.t(), String.t(), keyword()) :: boolean()
```

Returns whether a user exists.

Raises `TypeDB.Error` for anything other than a clean "not found" — an
unreachable server, a rejected token, a 500. A boolean cannot express "I could
not ask", and answering `false` to that question is the answer that makes a
caller do the wrong thing: `unless exists?(conn, x), do: create(conn, x)` would
try to create while the server is down. Use `get/2` if you would rather branch
on the error yourself.

# `get`

```elixir
@spec get(TypeDB.Connection.t(), String.t(), keyword()) ::
  {:ok, String.t()} | {:error, TypeDB.Error.t()}
```

Returns a username, or an error when the user does not exist.

# `get!`

```elixir
@spec get!(TypeDB.Connection.t(), String.t(), keyword()) :: String.t()
```

Returns a username, raising when the user does not exist.

# `list`

```elixir
@spec list(
  TypeDB.Connection.t(),
  keyword()
) :: {:ok, [String.t()]} | {:error, TypeDB.Error.t()}
```

Lists all usernames.

# `list!`

```elixir
@spec list!(
  TypeDB.Connection.t(),
  keyword()
) :: [String.t()]
```

Lists all usernames, raising on failure.

# `set_password`

```elixir
@spec set_password(TypeDB.Connection.t(), String.t(), String.t(), keyword()) ::
  :ok | {:error, TypeDB.Error.t()}
```

Replaces a user's password.

Existing tokens issued to that user are not revoked by this call; they expire
on their own schedule.

# `set_password!`

```elixir
@spec set_password!(TypeDB.Connection.t(), String.t(), String.t(), keyword()) :: :ok
```

Replaces a user's password, raising on failure.

---

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