{"id":18153,"library":"better-auth-cookie-consent","title":"Better Auth Cookie Consent","description":"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.","status":"active","version":"0.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/marcjulian/better-auth-plugins","tags":["javascript","typescript"],"install":[{"cmd":"npm install better-auth-cookie-consent","lang":"bash","label":"npm"},{"cmd":"yarn add better-auth-cookie-consent","lang":"bash","label":"yarn"},{"cmd":"pnpm add better-auth-cookie-consent","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency — this plugin extends Better Auth functionality","package":"better-auth","optional":false},{"reason":"optional peer for schema validation and type inference","package":"zod","optional":true}],"imports":[{"note":"ESM-only; CJS require will fail if package is ESM-only (check current setup)","wrong":"const cookieConsentPlugin = require('better-auth-cookie-consent')","symbol":"cookieConsentPlugin","correct":"import { cookieConsentPlugin } from 'better-auth-cookie-consent'"},{"note":"Client plugin is exported from '/client' subpath for proper tree-shaking","wrong":"import { cookieConsentClient } from 'better-auth-cookie-consent'","symbol":"cookieConsentClient","correct":"import { cookieConsentClient } from 'better-auth-cookie-consent/client'"},{"note":"exported from main package, not a subpath","wrong":"import { defaultConsentSchema } from 'better-auth-cookie-consent/schema'","symbol":"defaultConsentSchema","correct":"import { defaultConsentSchema } from 'better-auth-cookie-consent'"},{"note":"TypeScript type import — use `import type` to avoid runtime errors","wrong":"import { ConsentSchema } from 'better-auth-cookie-consent'","symbol":"type ConsentSchema","correct":"import type { ConsentSchema } from 'better-auth-cookie-consent'"}],"quickstart":{"code":"import { betterAuth } from 'better-auth';\nimport { cookieConsentPlugin, defaultConsentSchema } from 'better-auth-cookie-consent';\nimport { cookieConsentClient } from 'better-auth-cookie-consent/client';\n\n// Server setup\nexport const auth = betterAuth({\n  database: {\n    provider: 'sqlite',\n    url: 'file:./db.sqlite',\n  },\n  emailAndPassword: {\n    enabled: true,\n  },\n  plugins: [\n    cookieConsentPlugin({\n      schema: defaultConsentSchema,\n    }),\n  ],\n});\n\n// Client setup\nconst client = cookieConsentClient<typeof defaultConsentSchema>();\n\n// Example: set consent after user clicks accept\nawait client.setConsent({\n  functional: true,\n  analytics: false,\n  marketing: false,\n});\n\n// Example: get current consent\nconst consent = await client.getConsent();\nconsole.log('User consent:', consent);","lang":"typescript","description":"Shows complete server and client setup for cookie consent plugin with Zod schema validation"},"warnings":[{"fix":"Pin to exact version or watch changelog for breaking changes","message":"Initial release — API may change in minor versions before v1.0.0","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Use `import { cookieConsentClient } from 'better-auth-cookie-consent/client'`","message":"Client plugin must be imported from '/client' subpath, not from main package","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Ensure better-auth is at least ^1.5.0 in package.json","message":"Requires Better Auth v1.5.0+ — incompatible with older versions","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Pass a Zod schema to cookieConsentPlugin or cookieConsentClient for type safety","message":"Zod schema validation is optional but strongly recommended; omitting it may cause runtime type mismatches","severity":"deprecated","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Ensure you are using ESM (type: module in package.json) or add exports field support","cause":"Importing from a subpath that may not exist in CommonJS or older Node resolvers","error":"Error: Cannot find module 'better-auth-cookie-consent/client'"},{"fix":"Use ESM imports (import ...) or check if the package provides CJS fallback","cause":"Using CommonJS require() on an ESM-only package","error":"TypeError: cookieConsentPlugin is not a function"},{"fix":"Pass a schema: defaultConsentSchema or your own Zod schema to the plugin","cause":"cookieConsentPlugin called without a schema argument","error":"Uncaught Error: consentSchema is required"},{"fix":"Ensure consent object has boolean fields: { functional: true, analytics: false }","cause":"Using plain strings for consent values instead of booleans","error":"Type 'string' is not assignable to type 'boolean' in consent object"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}