The Better Auth InstantDB Adapter provides a seamless integration layer, allowing developers to utilize InstantDB as the backing database for Better Auth authentication services. This package, currently at version 1.3.2, facilitates complete authentication flows, automatic session synchronization between Better Auth and InstantDB, and offers type-safe development with TypeScript. While no explicit release cadence is stated, the presence of recent updates (e.g., v1.1.0 addressing email synchronization) suggests active maintenance. Its key differentiators include simplifying the complex task of managing user authentication data by offloading it to InstantDB, providing a customizable setup, and ensuring session consistency across client and server environments. It requires both `@instantdb/admin` for server-side operations and `better-auth` as core peer dependencies.
npm install better-auth-instantdbVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the basic server-side configuration of Better Auth to use InstantDB as its database, initializing the InstantDB admin client and integrating it via the `instantAdapter`.
For existing data, copy the `sync-emails.ts` script (available from the package repository or docs) to your project root and execute it. New sign-ins handle this automatically.
Carefully create and review your `instant.perms.ts` file, ensuring `allow` and `bind` rules are correctly defined for all auth-related entities (`users`, `accounts`, `sessions`, `verifications`). Refer to InstantDB documentation for best practices.
Ensure all required InstantDB application IDs and admin tokens are correctly set as environment variables, distinguishing between client-side (e.g., `NEXT_PUBLIC_`) and server-side variables.
Check that `process.env.VITE_INSTANT_APP_ID` (for server) or `process.env.NEXT_PUBLIC_INSTANT_APP_ID` (for client) are correctly set and accessible in your environment configuration.
Review and update your `instant.perms.ts` file. Ensure that roles for `users`, `accounts`, and `sessions` are correctly defined, particularly `bind` and `allow` rules, to permit Better Auth's operations.
Ensure `adminDb` (or your variable for the InstantDB admin client) is correctly initialized using `init({ schema, appId, adminToken, ... })` from `@instantdb/admin` and passed to `instantAdapter({ db: adminDb, ... })`.