betterauth
Installation
SKILL.md
Better Auth Integration Skill
This skill provides the source of truth for integrating Better Auth into a polyglot stack (Go backend + React frontend). It ensures secure session management, type-safe API calls, and seamless TanStack Query integration.
Architectural Standards
1. Unified Auth Schema & Plugins
- Database: Use the Better Auth standard schema. Standardize table names to
user,session,account,verification. - Plugins: Enable and configure:
organization: For multi-tenant isolation.sso: For SAML/OIDC enterprise login.two-factor: For TOTP/Email/SMS MFA.admin: For user impersonation and management.
2. Go Backend Integration (The Bridge)
- Middleware: Implement a robust middleware that:
- Extracts the
better-auth.session_tokencookie. - Validates it against the
sessiontable. - Handles Token Refresh by checking the
expiresAtand performing a silent refresh via the Better Auth API if needed.
- Extracts the
- Context: Store the full
UserandOrganizationobjects in the request context for downstream RBAC.