# asUser

> The user a call acts for.

`with noclick.as_user(user):` sets it for everything inside, sync or async:
`.aio` calls, tasks and `asyncio.to_thread`. A thread you start yourself
begins without it (a `contextvars` rule), so pass `user=` there. A
method's `user=` argument wins over it.

## asUser

```typescript
function asUser(user: UserRef | null, fn: () => T | Promise<T>): Promise<T>
```

Run `fn` acting for `user` (`null` = the account). Nests; the inner scope wins.

## currentUser

```typescript
function currentUser(): UserRef | null
```

The user set by the innermost `asUser` (or null).

Returns: What the innermost `as_user` was given, as given (nothing is looked up), or `None`
outside every `as_user` block, where calls act for your account.

Types:

```typescript
/** A `User` or your own id for the user. */
type UserRef = string | UserLike;

/** Anything that can name a user lazily (a `User`). */
interface UserLike {
  _userId(): Promise<string>;
}
```

## ALL_USERS

```typescript
const ALL_USERS: "all"
```

Every user plus account-level rows, for a read's `userFilter`.
## NO_USER

```typescript
const NO_USER: "none"
```

Account-level rows only (no user), for a read's `userFilter`.
