better-auth
Implement authentication and authorization with Better Auth - a framework-agnostic TypeScript authentication framework. Features include email/password authentication with verification, OAuth providers (Google, GitHub, Discord, etc.), two-factor authentication (TOTP, SMS),
Installation
Pick a client and clone the repository into its skills directory.
Installation
About this skill
Implement authentication and authorization with Better Auth - a framework-agnostic TypeScript authentication framework. Features include email/password authentication with verification, OAuth providers (Google, GitHub, Discord, etc.), two-factor authentication (TOTP, SMS), passkeys/WebAuthn support, session management, role-based access control (RBAC), rate limiting, and database adapters. Use when adding authentication to applications, implementing OAuth flows, setting up 2FA/MFA, managing user sessions, configuring authorization rules, or building secure authentication systems for web applications.
How to use
- Zainstaluj Better Auth za pomocą npm install better-auth (lub pnpm/yarn/bun add better-auth). 2. Utwórz plik .env w głównym katalogu projektu i dodaj dwie zmienne: BETTER_AUTH_SECRET (wygenerowany klucz 32 znaki) oraz BETTER_AUTH_URL (np. http://localhost:3000). 3. Stwórz plik auth.ts w głównym katalogu, w folderze lib/, utils/ lub src/app/server/ – będzie tam konfiguracja Better Auth. 4. W pliku auth.ts zaimportuj betterAuth z pakietu, następnie utwórz instancję z konfiguracją bazy danych, włącz emailAndPassword z opcją autoSignIn: true, oraz dodaj dostawców OAuth (np. GitHub z clientId i clientSecret z zmiennych środowiskowych). 5. Skonfiguruj integrację z bazą danych zgodnie z dokumentacją – Better Auth wspiera popularne bazy i ORMy. 6. Użyj obiektu auth w swoim kodzie aplikacji do obsługi logowania, rejestracji, zarządzania sesjami i autoryzacji użytkowników.