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

# Auth and current user

> Provide a CurrentUser service from request context.

This example turns oRPC context into an Effect service.

```ts title="auth.ts" theme={null}
import { Context, Effect } from "effect";
import { eos } from "effect-orpc";

class CurrentUser extends Context.Tag("CurrentUser")<
  CurrentUser,
  { id: string; role: "admin" | "member" }
>() {}

const authedProcedure = eos
  .$context<{ user: { id: string; role: "admin" | "member" } }>()
  .provide(CurrentUser, ({ context }) => Effect.succeed(context.user));

export const router = {
  me: authedProcedure.effect(function* () {
    return yield* CurrentUser;
  }),
};
```

## Use in middleware

```ts title="require-admin.ts" theme={null}
const adminProcedure = authedProcedure.use(function* () {
  const user = yield* CurrentUser;

  if (user.role !== "admin") {
    return yield* Effect.fail(new ForbiddenError());
  }
});
```

## Next step

Add structured errors with [Tagged errors example](/examples/tagged-errors).
