Better Auth RONIN Database Adapter

3.18.35 · active · verified Wed Apr 22

blade-better-auth (current stable version 3.18.35) functions as a specialized database adapter, integrating the `better-auth` authentication framework with RONIN databases. Its primary role is to facilitate the storage of session and user data within a RONIN backend by translating `better-auth`'s core schema requirements into RONIN's data modeling language. This package provides a `ronin()` factory function that can either operate with a default RONIN client instance or accept a custom `blade-client` instance, offering flexibility for advanced configurations like specific token management. The library ships with comprehensive TypeScript type definitions, ensuring type-safe development. Operating under a rapid versioning scheme, it undergoes continuous maintenance and updates, reflecting its active role within the RONIN ecosystem. It distinguishes itself by providing the specific bridge and schema translations necessary for this particular technology stack.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates initializing Better Auth with `blade-better-auth` using both a default and a custom RONIN client instance, highlighting common setup patterns for session management.

import { betterAuth } from 'better-auth';
import { ronin } from "blade-better-auth";
import { createSyntaxFactory } from 'blade-client';

// --- Option 1: Use the default RONIN client managed by the adapter ---
// This simplifies setup, assuming a default RONIN environment and config.
const authWithDefaultClient = betterAuth({
  database: ronin(), // Use the default RONIN client
  // ... other Better Auth configuration, e.g., providers, secrets
  secret: process.env.AUTH_SECRET ?? 'super-secret-dev-key', // Example secret for development
  callbacks: {
    async signIn({ user }) {
      console.log(`User ${user.email} signed in.`);
      return true;
    },
  },
});

// --- Option 2: Provide a custom RONIN client instance ---
// Useful for specific configurations, e.g., custom tokens, endpoints, or advanced client options.
const customClient = createSyntaxFactory({
  token: process.env.RONIN_TOKEN ?? '', // Ensure RONIN_TOKEN is set in environment for production
  // ... other blade-client configuration specific to your RONIN setup
});

const authWithCustomClient = betterAuth({
  database: ronin(customClient), // Pass the custom client instance
  // ... other Better Auth configuration
  secret: process.env.AUTH_SECRET ?? 'another-secret-dev-key',
  callbacks: {
    async redirect({ url, baseUrl }) {
      console.log(`Redirecting to ${url} from ${baseUrl}.`);
      return url;
    },
  },
});

console.log('Better Auth adapters initialized for different client types.');

// In a real application, you would typically export and use one of these instances
// within your API routes, server-side functions, or authentication middleware.
// export { authWithDefaultClient as auth };

view raw JSON →