πŸ“± Phone Validation in Better-Auth

Easily validate phones in Better-Auth with the Dymo API.

A better, simpler way to validate phones with Dymo API in a single line of code!

About Phone Validation

What is Phone Validation?

Please note that this feature may depend on plugins to function correctly.

Usage

To start validating phones registered in your project with Better-Auth, simply add this code to your plugin array.

import { dymoPhonePlugin } from "@dymo-api/better-auth";

export const auth = betterAuth({
    plugins: [
	    dymoPhonePlugin({ 
            apiKey: ""
        })
    ]
});

If you wish, you can set any value in the phone rules, customize them to your liking!

import { dymoPhonePlugin } from "@dymo-api/better-auth";

export const auth = betterAuth({
    plugins: [
	    dymoPhonePlugin({ 
            apiKey: "",
            phoneRules: {
                // These are the default rules defined for phone validation.
                deny: ["FRAUD", "INVALID"]
            },
            // You can disable phone normalization.
            // normalize: false
        })
    ]
});

Optional Flags

The plugin provides two optional flags:

  • applyToLogin (default: false): Apply validation to login endpoints (/sign-in/phone). We recommend enabling this to prevent blocked phones from logging in.
  • applyToOAuth (default: true): Apply validation to OAuth logins and registrations (/sign-up/oauth and /sign-in/oauth). Enabled by default.
  • normalize (default: true): Normalize phones. Enabled by default.

Examples with Flags

Enable login validation

import { dymoPhonePlugin } from "@dymo-api/better-auth";

export const auth = betterAuth({
    plugins: [
	    dymoPhonePlugin({ 
            apiKey: "",
            applyToLogin: true  // recommended
        })
    ]
});

Enable login and OAuth validation with custom rules

import { dymoPhonePlugin } from "@dymo-api/better-auth";

export const auth = betterAuth({
    plugins: [
	    dymoPhonePlugin({ 
            apiKey: "",
            applyToLogin: true,   // validate login phones
            applyToOAuth: true,   // validate OAuth phones
            phoneRules: {
                deny: ["FRAUD", "INVALID"]
            }
        })
    ]
});

Phone Rules

RuleDefaultPremiumDescription
FRAUDβœ…βŒFraud detection
INVALIDβœ…βŒInvalid phone format
COUNTRY:<COUNTRY_CODE>❌❌Block an phone based on its country; you must use ISO 3166-1 alpha-2.
HIGH_RISK_SCOREβŒβœ…High risk score detection

Parameters

ParameterTypeRequiredDescription
apiKeyStringβœ…Your Dymo API key to validate phones
phoneRulesPhone Rules[]❌Customize which phone rules to apply
applyToLoginBoolean❌Apply validation to login endpoints
applyToOAuthBoolean❌Apply validation to OAuth login/register
normalizeBoolean❌Normalize phones