π§ Email Validation in Better-Auth
Easily validate emails in Better-Auth with the Dymo API.
A better, simpler way to validate emails with Dymo API in a single line of code!
About Email Validation
What is Email Validation?
Please note that this feature may depend on plugins to function correctly.
Usage
To start validating emails registered in your project with Better-Auth, simply add this code to your plugin array.
import { dymoEmailPlugin } from "@dymo-api/better-auth";
export const auth = betterAuth({
plugins: [
dymoEmailPlugin({
apiKey: "PRIVATE_TOKEN_HERE"
})
]
});
If you wish, you can set any value in the email rules, customize them to your liking!
import { dymoEmailPlugin } from "@dymo-api/better-auth";
export const auth = betterAuth({
plugins: [
dymoEmailPlugin({
apiKey: "PRIVATE_TOKEN_HERE",
emailRules: {
// These are the default rules defined for email validation.
deny: ["FRAUD", "INVALID", "NO_MX_RECORDS", "NO_REPLY_EMAIL"]
},
// You can disable email normalization.
// normalize: false
})
]
});
Optional Flags
The plugin provides two optional flags:
applyToLogin(default:false): Apply validation to login endpoints (/sign-in/email). We recommend enabling this to prevent blocked emails 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 email addresses. Enabled by default.
Examples with Flags
Enable login validation
import { dymoEmailPlugin } from "@dymo-api/better-auth";
export const auth = betterAuth({
plugins: [
dymoEmailPlugin({
apiKey: "PRIVATE_TOKEN_HERE",
applyToLogin: true // recommended
})
]
});
Enable login and OAuth validation with custom rules
import { dymoEmailPlugin } from "@dymo-api/better-auth";
export const auth = betterAuth({
plugins: [
dymoEmailPlugin({
apiKey: "PRIVATE_TOKEN_HERE",
applyToLogin: true, // validate login emails
applyToOAuth: true, // validate OAuth emails
emailRules: {
deny: ["FRAUD", "INVALID", "NO_MX_RECORDS", "NO_REPLY_EMAIL"]
}
})
]
});
Email Rules
| Rule | Default | Premium | Description |
|---|---|---|---|
FRAUD | β | β | Fraud detection |
INVALID | β | β | Invalid phone format |
NO_MX_RECORDS | β | β | MX records check |
PROXIED_EMAIL | β | β | Email using proxy detection |
FREE_SUBDOMAIN | β | β | Email from free subdomain |
PERSONAL_EMAIL | β | β | Personal email vs corporate |
CORPORATE_EMAIL | β | β | Corporate email verification |
NO_REPLY_EMAIL | β | β | Detect no-reply email addresses |
ROLE_ACCOUNT | β | β | Role-based email detection |
NO_GRAVATAR | β | β | Gravatar profile detection |
NO_REACHABLE | β | β | Email unreachable |
HIGH_RISK_SCORE | β | β | High risk score detection |
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
apiKey | String | β | Your Dymo API key to validate emails |
emailRules | Email Rules[] | β | Customize which email rules to apply |
applyToLogin | Boolean | β | Apply validation to login endpoints |
applyToOAuth | Boolean | β | Apply validation to OAuth login/register |
normalize | Boolean | β | Normalize emails |