better-auth-cloudflare is a plugin designed to seamlessly integrate the Better Auth library with the Cloudflare ecosystem, including Workers, D1, Hyperdrive, KV, R2, and geolocation services. It is currently at version 0.3.0 and actively maintained with a continuous release cadence, addressing new features and compatibility updates. This library differentiates itself by providing out-of-the-box support for Cloudflare's serverless offerings, allowing developers to leverage D1 (SQLite), Postgres, and MySQL (via Drizzle ORM or native D1), KV for session caching, and R2 for file storage. It also automatically enriches user sessions with Cloudflare's geolocation and IP detection data, offering a comprehensive solution for authentication in Cloudflare environments without extensive manual setup, making it ideal for Hono, OpenNextJS, and other Worker-compatible frameworks.
npm install better-auth-cloudflareVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to integrate `better-auth-cloudflare` into a Cloudflare Worker using Hono, connecting to D1, KV, and R2 bindings, and accessing user session data including geolocation.
Ensure your `better-auth` installation is at version `^1.5.0` or higher. Run `npm install better-auth@^1.5.0` or `yarn add better-auth@^1.5.0`.
Install the new peer dependency: `npm install @better-auth/drizzle-adapter@^1.5.0` or `yarn add @better-auth/drizzle-adapter@^1.5.0`.
When configuring KV options, ensure any custom TTL values are 60 seconds (60000 milliseconds) or greater.
Ensure your R2 upload configurations explicitly pass `allowedMediaTypes` when calling upload functions, and that the client-side upload includes a correct and supported `Content-Type` header.
Migrate your project to use ES Modules. Use `import` statements instead of `require()`. Ensure your `package.json` specifies `"type": "module"` or uses `.mjs` file extensions.
Prefer `npm` for executing CLI commands. Use `npx better-auth-cloudflare@latest generate` instead of `bunx better-auth-cloudflare@latest generate`.