Better Auth DevTools

0.1.1-alpha.9 · active · verified Wed Apr 22

Better Auth DevTools is an unofficial development tool designed to augment the 'better-auth' library ecosystem. It provides utilities for managing test users, facilitating session switching, and offers a dedicated panel within React DevTools for enhanced debugging and interaction. Currently in an alpha state (version 0.1.1-alpha.9), the package is under active development, implying potential for frequent, unannounced breaking changes and API instability. It differentiates itself by offering direct integration with the 'better-auth' library, streamlining development workflows by providing direct control over authentication states and user management during local development and testing, significantly reducing manual setup time for various authentication scenarios. It serves as a crucial aid for developers working with authentication flows in React applications using 'better-auth'.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize both the standalone Better Auth DevTools client and integrate the React DevTools plugin into a TypeScript project, providing a foundation for managing authentication states and users during development.

import { BetterAuth } from 'better-auth';
import { BetterAuthDevTools } from 'better-auth-devtools/client';
import { createBetterAuthDevToolsPlugin } from 'better-auth-devtools/react';

// 1. Initialize your BetterAuth instance (replace with your actual configuration)
const betterAuthInstance = new BetterAuth({
  baseUrl: process.env.BETTER_AUTH_API_URL ?? 'https://api.example.com/auth',
  clientId: process.env.BETTER_AUTH_CLIENT_ID ?? 'your-client-id-here',
  // Add other BetterAuth configuration options as needed
});

// 2. Initialize the standalone Better Auth DevTools client
// This provides a separate UI for managing test users and sessions.
BetterAuthDevTools.init({
  betterAuthInstance,
  config: {
    // Example config: enable verbose logging for devtools
    debug: true,
    // Additional standalone client configuration options can go here
  },
});

console.log('Better Auth DevTools standalone client initialized.');

// 3. Create and implicitly register the React DevTools plugin
// This integrates a panel directly into the React Developer Tools extension.
// Simply importing and calling this function in your React app's entry point
// is often enough for the React DevTools extension to pick it up.
const reactDevToolsPlugin = createBetterAuthDevToolsPlugin({
  betterAuthInstance,
  config: {
    // Example config for the React panel: show more details
    showSessionDetails: true,
    // Additional React plugin configuration options
  },
});

console.log('Better Auth DevTools React plugin created and ready for React DevTools.');

// In a typical React application, ensure these initializations happen
// before your main React app renders, often in your 'index.tsx' or 'App.tsx'.

// Example of interacting with betterAuthInstance (for context, not part of devtools init)
async function logUserStatus() {
  try {
    const user = await betterAuthInstance.getCurrentUser();
    if (user) {
      console.log('User is logged in:', user.email);
    } else {
      console.log('No user currently logged in.');
    }
  } catch (error) {
    console.error('Failed to get user status:', error);
  }
}

// Uncomment to run an example auth check
// logUserStatus();

view raw JSON →