Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Integrate Better Auth — the comprehensive TypeScript-first authentication framework. Use when implementing authentication with Better Auth library, setting up OAuth, email/password, 2FA, passkeys, organizations, or migrating from other auth solutions. Note: Talent Architect uses Firebase Auth; this skill is for projects using Better Auth.
| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-02 | ✗→✓ | ▲ Improved | 71% | 0% |
| case-03 | ✗→✓ | ▲ Improved | 65% | 0% |
| case-10 | ✗→✓ | ▲ Improved | -6% | 0% |
| case-11 | ✗→✓ | ▲ Improved | 128% | 0% |
| case-12 | ✗→✓ | ▲ Improved | 74% | 0% |
TypeScript-first, framework-agnostic authentication framework entegrasyon rehberi.
Önemli: Talent Architect Firebase Auth kullanıyor. Bu skill Better Auth kullanan ayrı projeler içindir.
Resmi dokümantasyon: https://better-auth.com/docs
bashnpm install better-auth
bashBETTER_AUTH_SECRET=min-32-karakter-secret # openssl rand -base64 32 BETTER_AUTH_URL=https://example.com
Config'de yalnızca env var set edilmemişse baseURL/secret tanımla.
bashnpx @better-auth/cli@latest generate # Prisma/Drizzle için schema üret npx @better-auth/cli@latest migrate # Schema uygula (built-in adapter)
Plugin ekledikten sonra CLI'ı yeniden çalıştır.
typescript// lib/auth.ts import { betterAuth } from 'better-auth' import { drizzleAdapter } from 'better-auth/adapters/drizzle' export const auth = betterAuth({ database: drizzleAdapter(db, { provider: 'pg' }), emailAndPassword: { enabled: true, autoSignIn: true, sendResetPassword: async ({ user, url }) => { await sendEmail({ to: user.email, subject: 'Şifre Sıfırlama', body: url }) }, }, socialProviders: { github: { clientId: process.env.GITHUB_CLIENT_ID!, clientSecret: process.env.GITHUB_CLIENT_SECRET!, }, google: { clientId: process.env.GOOGLE_CLIENT_ID!, clientSecret: process.env.GOOGLE_CLIENT_SECRET!, }, }, session: { expiresIn: 60 * 60 * 24 * 7, // 7 gün updateAge: 60 * 60 * 24, // 1 günde bir refresh cookieCache: { enabled: true, maxAge: 60 * 5, // 5 dakika }, }, plugins: [], })
| Özellik | Plugin Gerekli | Kullanım | | ---------------------- | ---------------- | ---------------------- | | Email/Password | Hayır (built-in) | Temel auth | | OAuth (GitHub, Google) | Hayır (built-in) | Social login | | Email Verification | Hayır (built-in) | Email doğrulama | | Password Reset | Hayır (built-in) | Şifre sıfırlama | | Two-Factor Auth (TOTP) | twoFactor | Gelişmiş güvenlik | | Passkeys/WebAuthn | passkey | Passwordless | | Magic Link | magicLink | Email-based login | | Username Auth | username | Kullanıcı adı girişi | | Organizations | organization | Multi-tenant | | Rate Limiting | Hayır (built-in) | Kötüye kullanım önleme |
typescript// app/api/auth/[...all]/route.ts import { auth } from '@/lib/auth' import { toNextJsHandler } from 'better-auth/next-js' export const { GET, POST } = toNextJsHandler(auth)
typescript// lib/auth-client.ts import { createAuthClient } from 'better-auth/react' export const authClient = createAuthClient({ baseURL: process.env.NEXT_PUBLIC_APP_URL, }) export const { signIn, signUp, signOut, useSession } = authClient
typescript// components/LoginButton.tsx 'use client' import { authClient } from '@/lib/auth-client' export function LoginButton() { const { data: session } = authClient.useSession() if (session) { return ( <div> <span>{session.user.name}</span> <button onClick={() => authClient.signOut()}>Çıkış</button> </div> ) } return ( <div> <button onClick={() => authClient.signIn.social({ provider: 'google' })}> Google ile Giriş </button> <button onClick={() => authClient.signIn.social({ provider: 'github' })}> GitHub ile Giriş </button> </div> ) }
secondaryStorage tanımlanmışsa → session oraya gider (DB değil)session.storeSessionInDatabase: true → DB'ye de kaydetcookieCache → tamamen stateless| Strateji | Açıklama | Boyut | | ---------------------- | ---------------- | ------------ | | compact (varsayılan) | Base64url + HMAC | En küçük | | jwt | Standard JWT | Okunabilir | | jwe | Encrypted | Max güvenlik |
typescript// ✅ Tree-shaking için plugin-name yolu kullan import { twoFactor } from 'better-auth/plugins/two-factor' import { organization } from 'better-auth/plugins/organization' import { admin } from 'better-auth/plugins/admin' import { passkey } from 'better-auth/plugins/passkey' export const auth = betterAuth({ plugins: [twoFactor(), organization(), admin(), passkey()], })
typescriptexport const auth = betterAuth({ databaseHooks: { user: { create: { before: async (user) => { return { data: { ...user, role: 'user' } } }, after: async (user) => { await sendWelcomeEmail(user.email) }, }, }, }, })
typescript// middleware.ts import { auth } from '@/lib/auth' import { NextRequest, NextResponse } from 'next/server' export async function middleware(request: NextRequest) { const session = await auth.api.getSession({ headers: request.headers }) if (!session && request.nextUrl.pathname.startsWith('/dashboard')) { return NextResponse.redirect(new URL('/login', request.url)) } return NextResponse.next() } export const config = { matcher: ['/dashboard/:path*', '/api/protected/:path*'], }
typescript// Server tarafında session tipi type Session = typeof auth.$Infer.Session type User = typeof auth.$Infer.Session.user // Ayrı client/server projesi varsa import { createAuthClient } from 'better-auth/react' import type { auth } from './server/auth' const authClient = createAuthClient<typeof auth>()
better-auth paketi kurulduBETTER_AUTH_SECRET ve BETTER_AUTH_URL env var set edildinpx @better-auth/cli generate)sendVerificationEmail tanımlanmadan çalışmazbetter-auth/plugins değil better-auth/plugins/plugin-name kullanOther measured skills in the registry, with their headline benchmark lift.