> ## Documentation Index
> Fetch the complete documentation index at: https://confect.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

> Access the current user's identity in your Confect functions.

The `Auth` service provides access to the current user's identity. Unlike vanilla Convex (which returns `UserIdentity | null`), the Confect `Auth` service returns an `Effect` that fails with a typed error when no user is authenticated.

## Getting the user identity

```ts theme={null}
import * as Effect from "effect/Effect";
import { Auth } from "./confect/_generated/services";

Effect.gen(function* () {
  const auth = yield* Auth;

  const identity = yield* auth.getUserIdentity;
});
```

`getUserIdentity` succeeds with the user's [`UserIdentity`](https://docs.convex.dev/api/interfaces/server.UserIdentity) or fails with `NoUserIdentityFoundError`.

To require an authenticated user across a whole group of functions—and provide the loaded user to every handler—use [middleware](/v10/server/middleware) instead of repeating the lookup in each handler.

For authorization policies that differ only by allowed roles or a resource argument name, declare [middleware options](/v10/server/middleware#parameterizing-a-policy) rather than creating a separate middleware for every variation. One role gate can accept `{ admin: true }` on one function and `{ editor: true, admin: true }` on another. If you [repeat a guard](/v10/server/middleware#repeating-a-policy) on the same function, every attachment must pass.

## Handling unauthenticated requests

Use `Effect.catchTag` to handle the case where no user is logged in.

```ts theme={null}
Effect.gen(function* () {
  const auth = yield* Auth;

  const identity = yield* auth.getUserIdentity.pipe(
    Effect.catchTag("NoUserIdentityFoundError", () => Effect.succeed(null)),
  );
});
```

## Configuration

Auth provider configuration goes in `confect/auth.ts`, which is passed through to Convex as-is. See the [Convex auth documentation](https://docs.convex.dev/auth) for setup details.
