Better Auth InstantDB Adapter

1.3.2 · active · verified Wed Apr 22

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.

Common errors

Warnings

Install

Imports

Quickstart

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`.

import { betterAuth } from "better-auth"
import { instantAdapter } from "better-auth-instantdb"
import { init } from "@instantdb/admin"

// Mock schema and environment variables for demonstration
const schema = {}; // In a real app, this would be your InstantDB schema
process.env.VITE_INSTANT_APP_ID = process.env.VITE_INSTANT_APP_ID ?? 'your-app-id';
process.env.INSTANT_ADMIN_TOKEN = process.env.INSTANT_ADMIN_TOKEN ?? 'your-admin-token';

// Create InstantDB admin client
export const adminDb = init({
  schema,
  appId: process.env.VITE_INSTANT_APP_ID,
  adminToken: process.env.INSTANT_ADMIN_TOKEN,
  useDateObjects: true
})

// Create Better Auth instance with InstantDB adapter
export const auth = betterAuth({
  database: instantAdapter({
    db: adminDb,
    usePlural: true, // Optional: set to true if your schema uses plural table names
    debugLogs: false  // Optional: set to true to see detailed logs
  }),
  emailAndPassword: {
    enabled: true
  },
  // ... other Better Auth configuration options
});

console.log('Better Auth with InstantDB adapter initialized.');

view raw JSON →