Registry /
auth-security / better-auth-cookie-consent
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
cookieConsentPlugin
✓ import { cookieConsentPlugin } from 'better-auth-cookie-consent'
✗ const cookieConsentPlugin = require('better-auth-cookie-consent')
ESM-only; CJS require will fail if package is ESM-only (check current setup)
cookieConsentClient
✓ import { cookieConsentClient } from 'better-auth-cookie-consent/client'
✗ import { cookieConsentClient } from 'better-auth-cookie-consent'
Client plugin is exported from '/client' subpath for proper tree-shaking
defaultConsentSchema
✓ import { defaultConsentSchema } from 'better-auth-cookie-consent'
✗ import { defaultConsentSchema } from 'better-auth-cookie-consent/schema'
exported from main package, not a subpath
type ConsentSchema
✓ import type { ConsentSchema } from 'better-auth-cookie-consent'
✗ import { ConsentSchema } from 'better-auth-cookie-consent'
TypeScript type import — use `import type` to avoid runtime errors
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);
Errors
Common errors & fixes
Error: Cannot find module 'better-auth-cookie-consent/client'
Importing from a subpath that may not exist in CommonJS or older Node resolvers
fixEnsure you are using ESM (type: module in package.json) or add exports field support
TypeError: cookieConsentPlugin is not a function
Using CommonJS require() on an ESM-only package
fixUse ESM imports (import ...) or check if the package provides CJS fallback
Uncaught Error: consentSchema is required
cookieConsentPlugin called without a schema argument
fixPass a schema: defaultConsentSchema or your own Zod schema to the plugin
Type 'string' is not assignable to type 'boolean' in consent object
Using plain strings for consent values instead of booleans
fixEnsure consent object has boolean fields: { functional: true, analytics: false } Audit
Dependencies
better-authrequiredpeer dependency — this plugin extends Better Auth functionality
zodoptionaloptional peer for schema validation and type inference