Better Auth Cookie Consent

raw JSON →
0.1.1 verified Sat Apr 25 auth: no javascript

GDPR-compliant cookie consent management plugin for Better Auth (v0.1.1). Stores and manages user consent preferences for both anonymous and authenticated users, with automatic merge on sign-in/sign-up. Features consent versioning, Zod schema validation, and a generic client plugin for end-to-end type safety. Designed for the Better Auth ecosystem, actively developed.

error Error: Cannot find module 'better-auth-cookie-consent/client'
cause Importing from a subpath that may not exist in CommonJS or older Node resolvers
fix
Ensure you are using ESM (type: module in package.json) or add exports field support
error TypeError: cookieConsentPlugin is not a function
cause Using CommonJS require() on an ESM-only package
fix
Use ESM imports (import ...) or check if the package provides CJS fallback
error Uncaught Error: consentSchema is required
cause cookieConsentPlugin called without a schema argument
fix
Pass a schema: defaultConsentSchema or your own Zod schema to the plugin
error Type 'string' is not assignable to type 'boolean' in consent object
cause Using plain strings for consent values instead of booleans
fix
Ensure consent object has boolean fields: { functional: true, analytics: false }
breaking Initial release — API may change in minor versions before v1.0.0
fix Pin to exact version or watch changelog for breaking changes
gotcha Client plugin must be imported from '/client' subpath, not from main package
fix Use `import { cookieConsentClient } from 'better-auth-cookie-consent/client'`
gotcha Requires Better Auth v1.5.0+ — incompatible with older versions
fix Ensure better-auth is at least ^1.5.0 in package.json
deprecated Zod schema validation is optional but strongly recommended; omitting it may cause runtime type mismatches
fix Pass a Zod schema to cookieConsentPlugin or cookieConsentClient for type safety
npm install better-auth-cookie-consent
yarn add better-auth-cookie-consent
pnpm add better-auth-cookie-consent

Shows complete server and client setup for cookie consent plugin with Zod schema validation

import { betterAuth } from 'better-auth';
import { cookieConsentPlugin, defaultConsentSchema } from 'better-auth-cookie-consent';
import { cookieConsentClient } from 'better-auth-cookie-consent/client';

// Server setup
export const auth = betterAuth({
  database: {
    provider: 'sqlite',
    url: 'file:./db.sqlite',
  },
  emailAndPassword: {
    enabled: true,
  },
  plugins: [
    cookieConsentPlugin({
      schema: defaultConsentSchema,
    }),
  ],
});

// Client setup
const client = cookieConsentClient<typeof defaultConsentSchema>();

// Example: set consent after user clicks accept
await client.setConsent({
  functional: true,
  analytics: false,
  marketing: false,
});

// Example: get current consent
const consent = await client.getConsent();
console.log('User consent:', consent);