Other frameworks
Other Rust frameworks can call BetterAuth::handle_request. Convert the incoming method, path, headers, and body to an AuthRequest; then return the response status, bytes, and headers.
Forward the response
Section titled “Forward the response”This example uses HTTP types re-exported by Axum. append preserves repeated headers, including every Set-Cookie:
use crate::auth_schema::AppAuthSchema;use axum::http::{HeaderName, HeaderValue, Response};use better_auth::BetterAuth;use better_auth::prelude::AuthRequest;
async fn dispatch( auth: &BetterAuth<AppAuthSchema>, request: AuthRequest,) -> Result<Response<Vec<u8>>, Box<dyn std::error::Error>> { let result = auth.handle_request(request).await?; let mut response = Response::builder() .status(result.status) .body(result.body)?; for (name, value) in result.headers { response.headers_mut().append( HeaderName::from_bytes(name.as_bytes())?, HeaderValue::from_str(&value)?, ); } Ok(response)}Your host owns the dispatch future. If requests must finish after a disconnect, supervise them in an application-owned task. Cancelling dispatch can leave earlier database writes committed. The Axum integration and Poem integration provide this supervision automatically.
Trusted server operations
Section titled “Trusted server operations”BetterAuth::dispatch_endpoint accepts logical inputs and headers for trusted server calls. These operations stay on the server and do not create HTTP routes. See the integration contract for dispatch behavior.
Frontend
Section titled “Frontend”See the official Better Auth client documentation.