π± 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: "PRIVATE_TOKEN_HERE"
})
]
});
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: "PRIVATE_TOKEN_HERE",
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/oauthand/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: "PRIVATE_TOKEN_HERE",
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: "PRIVATE_TOKEN_HERE",
applyToLogin: true, // validate login phones
applyToOAuth: true, // validate OAuth phones
phoneRules: {
deny: ["FRAUD", "INVALID"]
}
})
]
});
Phone Rules
| Rule | Default | Premium | Description |
|---|---|---|---|
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
| Parameter | Type | Required | Description |
|---|---|---|---|
apiKey | String | β | Your Dymo API key to validate phones |
phoneRules | Phone Rules[] | β | Customize which phone rules to apply |
applyToLogin | Boolean | β | Apply validation to login endpoints |
applyToOAuth | Boolean | β | Apply validation to OAuth login/register |
normalize | Boolean | β | Normalize phones |