Registry / auth-security / better-auth-cookie-consent

better-auth-cookie-consent

JSON →
library0.1.1jsnpmunverified

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.

npm install better-auth-cookie-consent
INSTALL
IMPORT
SIG · BETTER-AUTH-COOKIE
B
better-auth-cookie-consent
auth-securityjavascriptv0.1.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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
musl
node 18226 runs
build_error
glibc
node 18226 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);
Debug
Known issues
breakingInitial release — API may change in minor versions before v1.0.0
fix
Pin to exact version or watch changelog for breaking changes
affects: <1.0.0
gotchaClient plugin must be imported from '/client' subpath, not from main package
fix
Use `import { cookieConsentClient } from 'better-auth-cookie-consent/client'`
affects: >=0.1.0
gotchaRequires Better Auth v1.5.0+ — incompatible with older versions
fix
Ensure better-auth is at least ^1.5.0 in package.json
affects: >=0.1.0
deprecatedZod 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
affects: >=0.1.0
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
fix
Ensure 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
fix
Use ESM imports (import ...) or check if the package provides CJS fallback
Uncaught Error: consentSchema is required
cookieConsentPlugin called without a schema argument
fix
Pass 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
fix
Ensure consent object has boolean fields: { functional: true, analytics: false }
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies
better-authrequiredpeer dependency — this plugin extends Better Auth functionality
zodoptionaloptional peer for schema validation and type inference
Agent activity
22 hits · last 30 days
node
20
OpenAI (training)
2
Resources
better-auth-cookie-consent — npm install better-auth-cookie-consent · libregistry