π IP Validation in Better-Auth
Easily validate IPs in Better-Auth with the Dymo API.
A better, simpler way to validate IPs with Dymo API in a single line of code!
About IP Validation
What is IP Validation?
Please note that this feature may depend on plugins to function correctly.
This feature is currently in the experimental phase and may fail until it reaches the stable version.
Usage
To start validating IPs registered in your project with Better-Auth, simply add this code to your plugin array.
import { dymoIPPlugin } from "@dymo-api/better-auth";
export const auth = betterAuth({
plugins: [
dymoIPPlugin({
apiKey: "PRIVATE_TOKEN_HERE"
})
]
});
If you wish, you can set any value in the IP rules, customize them to your liking!
import { dymoIPPlugin } from "@dymo-api/better-auth";
export const auth = betterAuth({
plugins: [
dymoIPPlugin({
apiKey: "PRIVATE_TOKEN_HERE",
ipRules: {
// These are the default rules defined for IP validation.
deny: ["FRAUD", "INVALID", "TOR_NETWORK"]
},
// You can disable IP 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 IPs 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 IPs. Enabled by default.
Examples with Flags
Enable login validation
import { dymoIPPlugin } from "@dymo-api/better-auth";
export const auth = betterAuth({
plugins: [
dymoIPPlugin({
apiKey: "PRIVATE_TOKEN_HERE",
applyToLogin: true // recommended
})
]
});
Enable login and OAuth validation with custom rules
import { dymoIPPlugin } from "@dymo-api/better-auth";
export const auth = betterAuth({
plugins: [
dymoIPPlugin({
apiKey: "PRIVATE_TOKEN_HERE",
applyToLogin: true, // validate login IPs
applyToOAuth: true, // validate OAuth IPs
ipRules: {
deny: ["FRAUD", "INVALID", "TOR_NETWORKS"]
}
})
]
});
IP Rules
| Rule | Default | Premium | Description |
|---|---|---|---|
FRAUD | β | β | Fraud detection |
INVALID | β | β | Invalid IP format |
TOR_NETWORK | β | β | Tor network detection |
COUNTRY:<COUNTRY_CODE> | β | β | Block an IP 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 IPs |
ipRules | IP Rules[] | β | Customize which IP rules to apply |
applyToLogin | Boolean | β | Apply validation to login endpoints |
applyToOAuth | Boolean | β | Apply validation to OAuth login/register |
normalize | Boolean | β | Normalize IPs |