Encriva for Developers

Better-Auth Enchanced/Plugins

Age Restriction

This plugin provides age verification and restriction features for Better Auth applications. It allows you to add age-based access restrictions to specific content or services.

Installation

import { ageRestriction, ageRestrictionClient } from "@encriva/better-auth-enchanced";

To use this plugin in your application, you need to register it in both client and server configurations.

Initialize plugin

auth.ts
export const auth = betterAuth({
  plugins: [
    ageRestriction()
  ]
});
auth-client.ts
const authClient = createAuthClient({
  plugins: [
    ageRestrictionClient()
  ]
});

Usage

To verify age:

authClient.ageRestriction.verify({
  birthdate: "1990-01-01"
});

To check age status:

authClient.ageRestriction.status();

API

PropTypeDefault
schema?
Record<string, any>
-
reverificationPeriod?
number
365
verificationMethods?
string[]
["birthdate"]
requireOnSignUp?
boolean
false
minimumAge?
number
18
enabled?
boolean
true

Error Codes

CodeDescription
AGE_VERIFICATION_REQUIREDAge verification is required
MINIMUM_AGE_REQUIREDYou need to meet the minimum age requirement
BIRTHDATE_REQUIREDBirthdate information is required
INVALID_BIRTHDATEInvalid birthdate
VERIFICATION_FAILEDAge verification failed
SYSTEM_DISABLEDAge restriction system is currently disabled

On this page