# buildTypedAuthBuilder

## Summary
Validate the assembled builder, initialize plugin context, construct middleware, and produce a ready-to-dispatch `AthenaAuth<DB>`.

## Symbol
- Name: `build`
- Original Symbol: `TypedAuthBuilder::build`
- Kind: `method`
- Owner: `TypedAuthBuilder`

## Signature
```rust
pub async fn build(self) -> AuthResult<AthenaAuth<DB>>
```

## Location
- `src/core/auth.rs`
- Re-exported type surface from `src/lib.rs`

## Inputs
- `self`: required; consumes the fully assembled typed builder

## Returns
- `Ok(AthenaAuth<DB>)` when configuration validation and plugin initialization succeed
- `Err(AuthError)` when configuration validation or initialization fails

## Errors
- Returns a config error when `AuthConfig::validate()` fails, including empty or shorter-than-32-character secrets
- Returns a config error when `.hook(...)` was used on the builder; the implementation requires callers to wrap the adapter with `HookedDatabaseAdapter` directly instead
- Propagates any error returned by a plugin's `on_init(&mut AuthContext<_>)`

## Preconditions
- The embedded `AuthConfig` must pass `validate()`
- The database adapter must be usable for constructing `SessionManager<DB>`
- Every registered plugin must initialize successfully against the shared context

## Side Effects
- Calls `plugin.on_init(&mut context).await` for each registered plugin
- Allocates shared `Arc` state for config and database references
- Constructs the built-in middleware chain and stores any custom middleware supplied earlier

## Guarantees
- Built-in middleware order is fixed as `BodyLimit -> RateLimit -> Csrf -> Cors`, followed by any custom middleware in the order they were added
- The resulting `AthenaAuth<DB>` shares the same database adapter through `Arc<DB>`
- The resulting `AthenaAuth<DB>` keeps plugin registration order intact for runtime dispatch
- This method does not process requests itself

## Examples
```rust
let auth = AuthBuilder::new(config)
    .database(MemoryDatabaseAdapter::new())
    .plugin(EmailPasswordPlugin::new().enable_signup(true))
    .build()
    .await?;
```

## Source of Truth
- Implementation: `src/core/auth.rs`
- Config validation: `crates/core/src/config.rs`, `src/__tests__/lib.rs`
- Usage examples: `examples/auth_builder_minimal.rs`, `examples/auth_core_ok.rs`
- Call sites: `tests/compatibility_tests.rs`, `src/tests/route_collision_precedence_tests.rs`
