better-auth-security-best-practices

Solid

Configure rate limiting, manage auth secrets, set up CSRF protection, define trusted origins, secure sessions and cookies, encrypt OAuth tokens, track IP addresses, and implement audit logging for Better Auth. Use when users need to secure their auth setup, prevent brute force attacks, or harden a Better Auth deployment.

API & Backend 45 stars 3 forks Updated today MIT

Install

View on GitHub

Quality Score: 84/100

Stars 20%
55
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

<!-- ๐Ÿ”’ LOCKED โ€” managed by clade ยท auto-generated by sync-to-cursor; edit source in .claude/ then re-run sync --> ## Secret Management ### Configuring the Secret ```ts import { betterAuth } from "better-auth"; export const auth = betterAuth({ secret: process.env.BETTER_AUTH_SECRET, // or via `BETTER_AUTH_SECRET` env }); ``` Better Auth looks for secrets in this order: 1. `options.secret` in your config 2. `BETTER_AUTH_SECRET` environment variable 3. `AUTH_SECRET` environment variable ### Secret Requirements - Rejects default/placeholder secrets in production - Warns if shorter than 32 characters or entropy below 120 bits - Generate: `openssl rand -base64 32` - Never commit secrets to version control ## Rate Limiting Enabled in production by default. Applies to all endpoints. Plugins can override per-endpoint. ### Default Configuration ```ts import { betterAuth } from "better-auth"; export const auth = betterAuth({ rateLimit: { enabled: true, // Default: true in production window: 10, // Time window in seconds (default: 10) max: 100, // Max requests per window (default: 100) }, }); ``` ### Storage Options Options: `"memory"` (resets on restart, avoid on serverless), `"database"` (persistent), `"secondary-storage"` (Redis, default when available). ```ts rateLimit: { storage: "database", } ``` ### Custom Storage Implement your own rate limit storage: ```ts rateLimit: { customStorage: { get: async (key) => { // Return { count: nu...

Details

Author
YuDefine
Repository
YuDefine/nuxt-supabase-starter
Created
7 months ago
Last Updated
today
Language
JavaScript
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content โ€” not just same category