better-auth-best-practices
यह क्या करती है
यह AI को Better Auth का सर्वर, क्लाइंट, डेटाबेस एडैप्टर, सेशन और एनवायरनमेंट वेरिएबल कॉन्फ़िगर करने के चरण समझाती है। यह TypeScript प्रोजेक्ट में ऑथेंटिकेशन जोड़ने वाले डेवलपर्स के लिए है।
कब इस्तेमाल करें
- ✓जब आप TypeScript ऐप में ईमेल और पासवर्ड या OAuth से लॉगिन जोड़ते हैं।
- ✓जब आप Better Auth की auth.ts फ़ाइल, डेटाबेस एडैप्टर या रूट हैंडलर सेट करते हैं।
- ✓जब आपको Better Auth प्लगइन जोड़ना हो या उसके एनवायरनमेंट वेरिएबल ठीक करने हों।
Skill का लिंक
https://github.com/trycompai/crm/blob/release/.agents/skills/better-auth-best-practices/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“क्या आप मेरे TypeScript ऐप में ईमेल और पासवर्ड वाला लॉगिन करने के लिए Better Auth सेट कर सकते हैं?”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
AI पैकेज इंस्टॉल करता है, सीक्रेट और URL वेरिएबल सेट करता है, ऑथ कॉन्फ़िगरेशन बनाता है, डेटाबेस माइग्रेशन चलाता है और हेल्थ एंडपॉइंट जाँचता है।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
Better Auth Integration Guide
Always consult better-auth.com/docs for code examples and latest API.
Setup Workflow
- Install:
npm install better-auth - Set env vars:
BETTER_AUTH_SECRETandBETTER_AUTH_URL - Create
auth.tswith database + config - Create route handler for your framework
- Run migrations:
- Built-in adapter:
npx @better-auth/cli@latest migrate - Drizzle:
npx @better-auth/cli@latest generate --output src/db/auth-schema.tsthennpx drizzle-kit push(dev) ornpx drizzle-kit generate && npx drizzle-kit migrate(prod) - Prisma:
npx @better-auth/cli@latest generate --output prisma/schema.prismathennpx prisma migrate dev
- Built-in adapter:
- Verify: call
GET /api/auth/ok— should return{ status: "ok" }
Quick Reference
Environment Variables
BETTER_AUTH_SECRET- Encryption secret (min 32 chars). Generate:openssl rand -base64 32BETTER_AUTH_URL- Base URL (e.g.,https://example.com)
Only define baseURL/secret in config if env vars are NOT set.
File Location
CLI looks for auth.ts in: ./, ./lib, ./utils, or under ./src. Use --config for custom path.
CLI Commands
npx @better-auth/cli@latest migrate- Apply schema (built-in adapter)npx @better-auth/cli@latest generate- Generate schema for Prisma/Drizzlenpx @better-auth/cli mcp --cursor- Add MCP to AI tools
Re-run after adding/changing plugins.
Core Config Options
| Option | Notes |
|---|---|
appName |
Optional display name |
baseURL |
Only if BETTER_AUTH_URL not set |
basePath |
Default /api/auth. Set / for root. |
secret |
Only if BETTER_AUTH_SECRET not set |
database |
Required for most features. See adapters docs. |
secondaryStorage |
Redis/KV for sessions & rate limits |
emailAndPassword |
{ enabled: true } to activate |
socialProviders |
{ google: { clientId, clientSecret }, ... } |
plugins |
Array of plugins |
trustedOrigins |
CSRF whitelist |
Database
Direct connections: Pass pg.Pool, mysql2 pool, better-sqlite3, or bun:sqlite instance. For Postgres, also supports postgres (postgres.js) and @neondatabase/serverless.
ORM adapters: Import from better-auth/adapters/drizzle, better-auth/adapters/prisma, better-auth/adapters/mongodb.
Drizzle provider values: "pg" (PostgreSQL), "mysql" (MySQL), "sqlite" (SQLite). Must match the driver used.
Critical: Better Auth uses adapter model names, NOT underlying table names. If Prisma model is User mapping to table users, use modelName: "user" (Prisma reference), not "users".
Session Management
Storage priority:
- If
secondaryStoragedefined → sessions go there (not DB) - Set
session.storeSessionInDatabase: trueto also persist to DB - No database +
cookieCache→ fully stateless mode
Cookie cache strategies:
compact(default) - Base64url + HMAC. Smallest.jwt- Standard JWT. Readable but signed.jwe- Encrypted. Maximum security.
Key options: session.expiresIn (default 7 days), session.updateAge (refresh interval), session.cookieCache.maxAge, session.cookieCache.version (change to invalidate all sessions).
User & Account Config
User: user.modelName, user.fields (column mapping), user.additionalFields, user.changeEmail.enabled (disabled by default), user.deleteUser.enabled (disabled by default).
Account: account.modelName, account.accountLinking.enabled, account.storeAccountCookie (for stateless OAuth).
Required for registration: email and name fields.
Email Flows
emailVerification.sendVerificationEmail- Must be defined for verification to workemailVerification.sendOnSignUp/sendOnSignIn- Auto-send triggersemailAndPassword.sendResetPassword- Password reset email handler
Security
In advanced:
useSecureCookies- Force HTTPS cookiesdisableCSRFCheck- ⚠️ Security riskdisableOriginCheck- ⚠️ Security riskcrossSubDomainCookies.enabled- Share cookies across subdomainsipAddress.ipAddressHeaders- Custom IP headers for proxiesdatabase.generateId- Custom ID generation or"serial"/"uuid"/false
Rate limiting: rateLimit.enabled, rateLimit.window, rateLimit.max, rateLimit.storage ("memory" | "database" | "secondary-storage").
Hooks
Endpoint hooks: `
अक्सर पूछे जाने वाले सवाल
कौन-से एनवायरनमेंट वेरिएबल चाहिए?
BETTER_AUTH_SECRET और BETTER_AUTH_URL चाहिए, और स्किल दिखाती है कि मज़बूत रैंडम सीक्रेट कैसे बनाएँ।
कौन-से डेटाबेस टूल सपोर्ट होते हैं?
यह बिल्ट-इन एडैप्टर, Drizzle और Prisma कवर करती है।
सेटअप ठीक चला, यह कैसे जाँचा जाता है?
यह auth हेल्थ रूट को कॉल करती है, जो ok स्टेटस लौटाना चाहिए।
जानकारी
लेखक का मूल विवरण
Configure Better Auth server and client, set up database adapters, manage sessions, add plugins, and handle environment variables. Use when users mention Better Auth, betterauth, auth.ts, or need to set up TypeScript authentication with email/password, OAuth, or plugin configuration.
repo: trycompai/crm
लोकप्रियता
- GitHub स्टार
- 12k
- रैंकिंग में स्थान
- #11509
- लाइसेंस
- MIT
- अपडेट की गई
- 1/11/2026
कमेंट
- …
इस repository की और skills
ai-elements
12kयह आपके एजेंट को बातचीत, संदेश, टूल डिस्प्ले और प्रॉम्प्ट इनपुट के लिए तैयार कॉम्पोनेंट से AI चैट इंटरफ़ेस बनाने में मदद करती है।
ai-sdk
12kयह आपके एजेंट को Vercel AI SDK से AI फ़ीचर बनाने में मदद करती है, जिसमें टेक्स्ट जनरेशन, स्ट्रीमिंग, टूल कॉलिंग और एजेंट शामिल हैं।
better-accessibility
12kयह आपके एजेंट को इंटरफ़ेस को कीबोर्ड और स्क्रीन रीडर के लिए उपयोगी बनाने में मदद करती है, जिसमें फ़ोकस, लेबल, ARIA और फ़ॉर्म शामिल हैं।
better-colors
12kयह आपके एजेंट को वेब इंटरफ़ेस के लिए रंग बदलने, चुनने और जाँचने में मदद करती है, जिसमें OKLCH पैलेट, कॉन्ट्रास्ट और डार्क मोड शामिल हैं।
मिलती-जुलती skills
reverse-engineer-anything
422kयह आपके एजेंट को REA टूल से शिप हुई ऐप्स और पैकेज को अंदर से समझने, वर्ज़न की तुलना करने या दोबारा बनाने में मदद करती है।
1password
394kयह आपके एजेंट को 1Password CLI सेट करने, साइन इन करने और सीक्रेट्स की वैल्यू चैट में छापे बिना उन्हें पढ़ने या इस्तेमाल करने में मदद करती है।
healthcheck
394kयह आपके एजेंट को उस कंप्यूटर या सर्वर का सुरक्षा ऑडिट करने देती है जिस पर OpenClaw चलता है, जिसमें SSH, firewall, अपडेट और बैकअप शामिल हैं, और फिर सुरक्षित सुधार सुझाती है।