> ## 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

> Effect services for Convex identity lookup and JWT signing.

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](https://confect.dev/server/middleware.md) 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](https://confect.dev/server/middleware.md#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](https://confect.dev/server/middleware.md#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.

## Signing deployment JWTs

Confect exposes [Convex's `ctx.auth.signJwt()`](https://docs.convex.dev/api/interfaces/server.MutationAuth) through the separate `MutationAuth` service in `confect/_generated/services`; `Auth` remains identity-only. `MutationAuth.signJwt(options)` returns a lazy `Effect<string>` instead of a Promise. Native rejections become defects rather than typed errors.

Confect checks the signing capability at compile time: only mutation handlers and middleware implementations restricted to mutations can require `MutationAuth`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.