npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

better-auth-harmony

v1.3.1

Published

Validation and normalization for better-auth

Readme

A better-auth plugin for email & phone normalization and additional validation, blocking over 55,000 temporary email domains.

Email normalization: [email protected] -> [email protected]
Phone normalization: +1 (555) 123-1234 -> +15551231234
Validation: [email protected] -> Blocked

Email

Getting Started

1. Install the plugin

npm i better-auth-harmony

2. Add the plugin to your auth config

// auth.ts
import { betterAuth } from 'better-auth';
import { emailHarmony } from 'better-auth-harmony';

export const auth = betterAuth({
  // ... other config options
  plugins: [emailHarmony()]
});

3. Migrate the database

npx @better-auth/cli migrate

or

npx @better-auth/cli generate

See the Schema section to add the fields manually.

Troubleshooting ESM

The validator.js package lacks proper ESM support. Please open an issue in this repo if the following workarounds don't help.

Next.js

Add better-auth-harmony to transpilePackages in next.config

Vite

Add better-auth-harmony to ssr.noExternal in vite.config

Workarounds

  • Use NodeJs 22 or higher
  • Or use NODE_OPTIONS=--experimental-detect-module for Node >= 20.10

Either as an environment variable, or via:

npx --node-options=--experimental-detect-module @better-auth/cli generate

or as a local script in package.json:

{
  "scripts": {
    "auth-generate": "NODE_OPTIONS=--experimental-detect-module cli generate"
  }
}

If none of the above works, consider yarn patch or npm patch-package to add "type": "module" to validator's package.json.

Options

  • allowNormalizedSignin (default=false) - Allow logging in with any version of the unnormalized email address. For example, a user who signed up with the email [email protected] may also log in with [email protected]. Makes 1 extra database query for every login attempt.
  • validator - Custom function to validate email. By default uses validator.js and Mailchecker.
  • normalizer - Custom function to normalize the email address. By default uses validator.js/normalizeEmail().
  • matchers - Customize when to run input email validation and normalization. Normalization always runs on user creation and update regardless of this setting.

Schema

The emailHarmony plugin requires an additional field in the user table:

| Field Name | Type | Optional | Unique | Description | | --------------- | ------ | -------- | ------ | ---------------------------------------- | | normalizedEmail | string | True | True | User's email address after normalization |

The normalizedEmail field being unique prevents users from signing up with throwaway variations of the same email address.


Phone number

[!NOTE] Unlike emailHarmony, phone number normalization intercepts and modifies the user's phoneNumber, permitting only normalized numbers in the backend.

Getting Started

1. Install the plugin

npm i better-auth-harmony
2. Add the plugin to your auth config
// auth.ts
import { betterAuth } from 'better-auth';
import { phoneNumber } from 'better-auth/plugins';
import { phoneHarmony } from 'better-auth-harmony';

export const auth = betterAuth({
  // ... other config options
  plugins: [phoneNumber(), phoneHarmony()]
});

See the better-auth phoneNumber plugin documentation for information on configuring the phoneNumber(), including validation.

Options

  • defaultCountry - Default country for numbers written in non-international form (without a + sign).
  • defaultCallingCode - Default calling code for numbers written in non-international form (without a + sign). Useful for parsing non-geographic codes such as +800 numbers.
  • extract (default=true) - Defines the "strictness" of parsing a phone number. By default, it will attempt to extract the phone number from any input string, such as "My phone number is (213) 373-4253".
  • acceptRawInputOnError (default=false) - If the normalizer throws, for example because it is unable to parse the phone number, use the original input. For example, the phone number "+12" will be saved as-is to the database.
  • normalizer - Custom function to normalize phone number. Default uses parsePhoneNumberWithError from libphonenumber-js/max. Can be used to infer the country through the Request object, for example using IP address geolocation.
  • matchers - Customize when to run input phoneNumber validation.