Plugins

Legal Consent

Legal Consent plugin for Better Auth Kit

Require your users to accept the required compliances before they can sign up.

Supported compliances include:

  • Terms of Service
  • Privacy Policy
  • Age Verification
  • Marketing Consent
  • Cookie Consent

This plugin does not come with UI, this is purely functionality. We recommend checking out our UI components registry to implement shadcn styled components.

1. Installation

npm install @better-auth-kit/legal-consent

2. Initialize

auth.ts
import { legalConsent } from "@better-auth-kit/legal-consent";
 
export const auth = betterAuth({
  plugins: [
    legalConsent({
      requireTOS: true,
      requirePrivacyPolicy: true,
      requireAgeVerification: true,
      requireMarketingConsent: true,
      requireCookieConsent: true,
    }),
  ],
});

3. Sign up methods

Add the following methods to your sign up page.

sign-up.tsx
authClient.signUp.email({
  email: "some_email@example.com",
  password: "some_password",
  tosAccepted: true,
  privacyPolicyAccepted: true,
  ageVerified: true,
  marketingConsentAccepted: true,
  cookieConsentAccepted: true,
});

What does it do?

By utilizing the legalConsent plugin, you can require the following legal consents on your sign-up routes:

  • Terms of Service
  • Privacy Policy
  • Age Verification
  • Marketing Consent
  • Cookie Consent

Whenever a user signs up, the plugin requires you to pass additional data to the signup method. The data can vary depending on the legal consent requirements you have set. For example, if you require the user to accept the terms of service, you must pass tosAccepted: true to the signup method. After the plugin has verified the given data is all valid, it will pass those legal consent values to the user data that will be created.

Options

You can enable the following legal compliance options:

legalConsent({
  tosAccepted: true,
  privacyPolicyAccepted: true,
  ageVerified: true,
  marketingConsentAccepted: true,
  cookieConsentAccepted: true
});

Configuring the schema

You can configure the name of these fields by passing the schema option to the plugin.

legalConsent({
  schema: {
    userModelName: "user",
    tosAccepted: "tosAccepted",
    privacyPolicyAccepted: "privacyPolicyAccepted",
    ageVerified: "ageVerified",
    marketingConsentAccepted: "marketingConsentAccepted",
    cookieConsentAccepted: "cookieConsentAccepted",
  },
});

Schema

Table: user

Note: Not all keys will be in the table as it depends on if you enabled each compliance, as well as if you changed the name of a given schema field.

Field NameTypeKeyDescription
tosAccepted
boolean
-Wether the user accepted the TOS.
requirePrivacyPolicy
boolean
-Wether the user accepted the privacy policy.
requireAgeVerification
boolean
-Wether the user accepted the age verification.
requireMarketingConsent
boolean
-Wether the user accepted the marketing consent.
requireCookieConsent
boolean
-Wether the user accepted the cookie consent.

On this page