Skip to main content
This crate does not reimplement Better Auth. You build the Axum router from better-auth.rs in your app, then nest it and protect nestrs handlers with BetterAuthGuard. The crate does not depend on a specific better-auth package so MSRV 1.88 stays intact.

Install

Nest the auth router

BetterAuthModule::for_root returns a DynamicModule that mounts auth_router at options.path (default /api/auth). Merge it with NestFactory::create_with_modules:

Guard

BetterAuthGuard implements CanActivate. It looks at the raw Cookie header (no extra cookie crate), so it works whether or not NestApplication::use_cookies is on. Missing or empty cookie → 401 unauthorized.

Options

path is normalized to an absolute prefix without a trailing slash ("api/auth""/api/auth").