Better Auth Harmony

1.3.2 · active · verified Wed Apr 22

Better Auth Harmony is a plugin for the `better-auth` framework, designed to enhance user input handling by providing robust validation and normalization functionalities. It specifically targets email addresses, detecting and blocking disposable domains, as well as standardizing phone numbers. The library aims to improve data quality and security within applications leveraging `better-auth` for user authentication. The current stable version is `1.3.2`, with a release cadence that includes regular patch and minor updates to address bugs and introduce new features. Its primary differentiator lies in its deep integration with the `better-auth` ecosystem, offering specialized validation and normalization that aligns with `better-auth`'s architecture, thereby providing a comprehensive solution for managing user identity data.

Common errors

Warnings

Install

Imports

Quickstart

This code demonstrates how to integrate `emailHarmony` and `phoneHarmony` plugins into a `better-auth` instance. It showcases the plugin-based configuration and highlights automatic normalization and validation features.

import { betterAuth } from 'better-auth';
import { emailHarmony, phoneHarmony } from 'better-auth-harmony';
import { phoneNumber } from 'better-auth/plugins'; // Assuming this is needed for phone number handling in better-auth

// Configure your Better Auth instance with the Harmony plugins
export const auth = betterAuth({
  // ... other better-auth configuration options
  emailAndPassword: {
    enabled: true,
  },
  plugins: [
    emailHarmony({
      allowNormalizedSignin: true, // Example option: Allow users to sign in with normalized or unnormalized emails
    }),
    phoneNumber(), // better-auth's core phone number plugin
    phoneHarmony({
      matchers: { // Example matcher, customize as needed
        create: true,
        update: true,
        delete: false,
      },
    }),
  ],
  // Define a database adapter (e.g., Prisma, Drizzle)
  // database: prismaAdapter(prisma, { provider: 'postgresql' }),
});

console.log('Better Auth instance configured with Harmony plugins.');
console.log('Harmony automatically normalizes and validates emails/phone numbers.');
console.log('For example, "foo+temp@gmail.com" becomes "foo@gmail.com" and checks for disposable domains.');

view raw JSON →