[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M77QF5Q7RFCQ55M48H2NHXGE":3,"skill-same:01M77QF5Q7RFCQ55M48H2NHXGE":46},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":30,"ownerDescription":6,"updatedAt":31,"install":32,"resources":45},"01M77QF5Q7RFCQ55M48H2NHXGE","create-auth",null,"Scaffold and implement authentication in TypeScript\u002FJavaScript apps using Better Auth. Detect frameworks, configure database adapters, set up route handlers, add OAuth providers, and create auth UI pages. Use when users want to add login, sign-up, or authentication to a new or existing project with Better Auth.","Reihantt6\u002Fsns-myagent","Reihantt6","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F219822095?v=4","01M77KK94PV8B7C2D9XWXNS8DJ","Mohamad Reihan tegar prasetya","01M77KK958QFMTHYXGXFV7KZ79",2,"MIT","https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent\u002Fblob\u002Fmain\u002Fagent\u002Fskills\u002Fcreate-auth\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\ndescription: \"Scaffold and implement authentication in TypeScript\u002FJavaScript apps using Better Auth. Detect frameworks, configure database adapters, set up route handlers, add OAuth providers, and create auth UI pages. Use when users want to add login, sign-up, or authentication to a new or existing project with Better Auth.\"\n---\n# Create Auth Skill\n\nGuide for adding authentication to TypeScript\u002FJavaScript applications using Better Auth.\n\n**For code examples and syntax, see [better-auth.com\u002Fdocs](https:\u002F\u002Fbetter-auth.com\u002Fdocs).**\n\n---\n\n## Phase 1: Planning (REQUIRED before implementation)\n\nBefore writing any code, gather requirements by scanning the project and asking the user structured questions. This ensures the implementation matches their needs.\n\n### Step 1: Scan the project\n\nAnalyze the codebase to auto-detect:\n- **Framework** — Look for `next.config`, `svelte.config`, `nuxt.config`, `astro.config`, `vite.config`, or Express\u002FHono entry files.\n- **Database\u002FORM** — Look for `prisma\u002Fschema.prisma`, `drizzle.config.ts`, `package.json` deps (`pg`, `postgres`, `@neondatabase\u002Fserverless`, `mysql2`, `better-sqlite3`, `mongoose`, `mongodb`). If `drizzle.config.ts` exists, read its `dialect` field to determine the DB type (e.g., `\"postgresql\"` → Drizzle + Postgres). Also check which Drizzle driver is installed (`drizzle-orm\u002Fnode-postgres` → `pg`, `drizzle-orm\u002Fpostgres-js` → `postgres`, `drizzle-orm\u002Fneon-http` → Neon).\n- **Existing auth** — Look for existing auth libraries (`next-auth`, `lucia`, `clerk`, `supabase\u002Fauth`, `firebase\u002Fauth`) in `package.json` or imports.\n- **Package manager** — Check for `pnpm-lock.yaml`, `yarn.lock`, `bun.lockb`, or `package-lock.json`.\n\nUse what you find to pre-fill defaults and skip questions you can already answer.\n\n### Step 2: Ask planning questions\n\nUse the `AskQuestion` tool to ask the user **all applicable questions in a single call**. Skip any question you already have a confident answer for from the scan. Group them under a title like \"Auth Setup Planning\".\n\n**Questions to ask:**\n\n1. **Project type** (skip if detected)\n   - Prompt: \"What type of project is this?\"\n   - Options: New project from scratch | Adding auth to existing project | Migrating from another auth library\n\n2. **Framework** (skip if detected)\n   - Prompt: \"Which framework are you using?\"\n   - Options: Next.js (App Router) | Next.js (Pages Router) | SvelteKit | Nuxt | Astro | Express | Hono | SolidStart | Other\n\n3. **Database & ORM** (skip if detected)\n   - Prompt: \"Which database setup will you use?\"\n   - Options: PostgreSQL (Prisma) | PostgreSQL (Drizzle) | PostgreSQL (pg driver) | MySQL (Prisma) | MySQL (Drizzle) | MySQL (mysql2 driver) | SQLite (Prisma) | SQLite (Drizzle) | SQLite (better-sqlite3 driver) | MongoDB (Mongoose) | MongoDB (native driver)\n\n4. **Authentication methods** (always ask, allow multiple)\n   - Prompt: \"Which sign-in methods do you need?\"\n   - Options: Email & password | Social OAuth (Google, GitHub, etc.) | Magic link (passwordless email) | Passkey (WebAuthn) | Phone number\n   - `allow_multiple: true`\n\n5. **Social providers** (only if they selected Social OAuth above — ask in a follow-up call)\n   - Prompt: \"Which social providers do you need?\"\n   - Options: Google | GitHub | Apple | Microsoft | Discord | Twitter\u002FX\n   - `allow_multiple: true`\n\n6. **Email verification** (only if Email & password was selected above — ask in a follow-up call)\n   - Prompt: \"Do you want to require email verification?\"\n   - Options: Yes | No\n\n7. **Email provider** (only if email verification is Yes, or if Password reset is selected in features — ask in a follow-up call)\n   - Prompt: \"How do you want to send emails?\"\n   - Options: Resend | Mock it for now (console.log)\n\n8. **Features & plugins** (always ask, allow multiple)\n   - Prompt: \"Which additional features do you need?\"\n   - Options: Two-factor authentication (2FA) | Organizations \u002F teams | Admin dashboard | API bearer tokens | Password reset | None of these\n   - `allow_multiple: true`\n\n9. **Auth pages** (always ask, allow multiple — pre-select based on earlier answers)\n   - Prompt: \"Which auth pages do you need?\"\n   - Options vary based on previous answers:\n     - Always available: Sign in | Sign up\n     - If Email & password selected: Forgot password | Reset password\n     - If email verification enabled: Email verification\n   - `allow_multiple: true`\n\n10. **Auth UI style** (always ask)\n   - Prompt: \"What style do you want for the auth pages? Pick one or describe your own.\"\n   - Options: Minimal & clean | Centered card with background | Split layout (form + hero image) | Floating \u002F glassmorphism | Other (I'll describe)\n\n### Step 3: Summarize the plan\n\nAfter collecting answers, present a concise implementation plan as a markdown checklist. Example:\n\n```\n## Auth Implementation Plan\n\n- **Framework:** Next.js (App Router)\n- **Database:** PostgreSQL via Prisma\n- **Auth methods:** Email\u002Fpassword, Google OAuth, GitHub OAuth\n- **Plugins:** 2FA, Organizations, Email verification\n- **UI:** Custom forms\n\n### Steps\n1. Install `better-auth` and `@better-auth\u002Fcli`\n2. Create `lib\u002Fauth.ts` with server config\n3. Create `lib\u002Fauth-client.ts` with React client\n4. Set up route handler at `app\u002Fapi\u002Fauth\u002F[...all]\u002Froute.ts`\n5. Configure Prisma adapter and generate schema\n6. Add Google & GitHub OAuth providers\n7. Enable `twoFactor` and `organization` plugins\n8. Set up email verification handler\n9. Run migrations\n10. Create sign-in \u002F sign-up pages\n```\n\nAsk the user to confirm the plan before proceeding to Phase 2.\n\n---\n\n## Phase 2: Implementation\n\nOnly proceed here after the user confirms the plan from Phase 1.\n\nFollow the decision tree below, guided by the answers collected above.\n\n```\nIs this a new\u002Fempty project?\n├─ YES → New project setup\n│   1. Install better-auth (+ scoped packages per plan)\n│   2. Create auth.ts with all planned config\n│   3. Create auth-client.ts with framework client\n│   4. Set up route handler\n│   5. Set up environment variables\n│   6. Run CLI migrate\u002Fgenerate\n│   7. Add plugins from plan\n│   8. Create auth UI pages\n│\n├─ MIGRATING → Migration from existing auth\n│   1. Audit current auth for gaps\n│   2. Plan incremental migration\n│   3. Install better-auth alongside existing auth\n│   4. Migrate routes, then session logic, then UI\n│   5. Remove old auth library\n│   6. See migration guides in docs\n│\n└─ ADDING → Add auth to existing project\n    1. Analyze project structure\n    2. Install better-auth\n    3. Create auth config matching plan\n    4. Add route handler\n    5. Run schema migrations\n    6. Integrate into existing pages\n    7. Add planned plugins and features\n```\n\nAt the end of implementation, guide users thoroughly on remaining next steps (e.g., setting up OAuth app credentials, deploying env vars, testing flows).\n\n---\n\n## Installation\n\n**Core:** `npm install better-auth`\n\n**Scoped packages (as needed):**\n| Package | Use case |\n|---------|----------|\n| `@better-auth\u002Fpasskey` | WebAuthn\u002FPasskey auth |\n| `@better-auth\u002Fsso` | SAML\u002FOIDC enterprise SSO |\n| `@better-auth\u002Fstripe` | Stripe payments |\n| `@better-auth\u002Fscim` | SCIM user provisioning |\n| `@better-auth\u002Fexpo` | React Native\u002FExpo |\n\n---\n\n## Environment Variables\n\n```env\nBETTER_AUTH_SECRET=\u003C32+ chars, generate with: openssl rand -base64 32>\nBETTER_AUTH_URL=http:\u002F\u002Flocalhost:3000\nDATABASE_URL=\u003Cyour database connection string>\n```\n\nAdd OAuth secrets as needed: `GITHUB_CLIENT_ID`, `GITHUB_CLIENT_SECRET`, `GOOGLE_CLIENT_ID`, etc.\n\n---\n\n## Server Config (auth.ts)\n\n**Location:** `lib\u002Fauth.ts` or `src\u002Flib\u002Fauth.ts`\n\n**Minimal config needs:**\n- `database` - Connection or adapter\n- `emailAndPassword: { enabled: true }` - For email\u002Fpassword auth\n\n**Standard config adds:**\n- `socialProviders` - OAuth providers (google, github, etc.)\n- `emailVerification.sendVerificationEmail` - Email verification handler\n- `emailAndPassword.sendResetPassword` - Password reset handler\n\n**Full config adds:**\n- `plugins` - Array of feature plugins\n- `session` - Expiry, cookie cache settings\n- `account.accountLinking` - Multi-provider linking\n- `rateLimit` - Rate limiting config\n\n**Export types:** `export type Session = typeof auth.$Infer.Session`\n\n---\n\n## Client Config (auth-client.ts)\n\n**Import by framework:**\n| Framework | Import |\n|-----------|--------|\n| React\u002FNext.js | `better-auth\u002Freact` |\n| Vue | `better-auth\u002Fvue` |\n| Svelte | `better-auth\u002Fsvelte` |\n| Solid | `better-auth\u002Fsolid` |\n| Vanilla JS | `better-auth\u002Fclient` |\n\n**Client plugins** go in `createAuthClient({ plugins: [...] })`.\n\n**Common exports:** `signIn`, `signUp`, `signOut`, `useSession`, `getSession`\n\n---\n\n## Route Handler Setup\n\n| Framework | File | Handler |\n|-----------|------|---------|\n| Next.js App Router | `app\u002Fapi\u002Fauth\u002F[...all]\u002Froute.ts` | `toNextJsHandler(auth)` → export `{ GET, POST }` |\n| Next.js Pages | `pages\u002Fapi\u002Fauth\u002F[...all].ts` | `toNextJsHandler(auth)` → default export |\n| Express | Any file | `app.all(\"\u002Fapi\u002Fauth\u002F*\", toNodeHandler(auth))` |\n| SvelteKit | `src\u002Fhooks.server.ts` | `svelteKitHandler(auth)` |\n| SolidStart | Route file | `solidStartHandler(auth)` |\n| Hono | Route file | `auth.handler(c.req.raw)` |\n\n**Next.js Server Components:** Add `nextCookies()` plugin to auth config.\n\n---\n\n## Database Migrations\n\n| Adapter | Command |\n|---------|---------|\n| Built-in Kysely | `npx @better-auth\u002Fcli@latest migrate` (applies directly) |\n| Prisma | `npx @better-auth\u002Fcli@latest generate --output prisma\u002Fschema.prisma` then `npx prisma migrate dev` |\n| Drizzle (dev) | `npx @better-auth\u002Fcli@latest generate --output src\u002Fdb\u002Fauth-schema.ts` then `npx drizzle-kit push` |\n| Drizzle (prod) | `npx @better-auth\u002Fcli@latest generate --output src\u002Fdb\u002Fauth-schema.ts` then `npx drizzle-kit generate` then `npx drizzle-kit migrate` |\n\n> **Note:** `drizzle-kit push` skips migration files and is only safe for development. Use `drizzle-kit generate` + `drizzle-kit migrate` in production.\n\n**Re-run after adding plugins.**\n\n---\n\n## Database Adapters\n\n| Database | Setup |\n|----------|-------|\n| SQLite | Pass `better-sqlite3` or `bun:sqlite` instance directly |\n| PostgreSQL | Pass `pg.Pool` instance directly |\n| MySQL | Pass `mysql2` pool directly |\n| Prisma | `prismaAdapter(prisma, { provider: \"postgresql\" })` from `better-auth\u002Fadapters\u002Fprisma` |\n| Drizzle (pg) | `drizzleAdapter(db, { provider: \"pg\" })` from `better-auth\u002Fadapters\u002Fdrizzle` |\n| Drizzle (mysql) | `drizzleAdapter(db, { provider: \"mysql\" })` from `better-auth\u002Fadapters\u002Fdrizzle` |\n| Drizzle (sqlite) | `drizzleAdapter(db, { provider: \"sqlite\" })` from `better-auth\u002Fadapters\u002Fdrizzle` |\n| MongoDB | `mongodbAdapter(db)` from `better-auth\u002Fadapters\u002Fmongodb` |\n\n### Drizzle + PostgreSQL Setup\n\nBefore using `drizzleAdapter`, initialize the `db` instance:\n\n```ts\n\u002F\u002F Option 1: node-postgres (pg)\nimport { drizzle } from \"drizzle-orm\u002Fnode-postgres\"\nimport { Pool } from \"pg\"\nimport * as schema from \".\u002Fauth-schema\"\n\nconst pool = new Pool({ connectionString: process.env.DATABASE_URL })\nexport const db = drizzle(pool, { schema })\n```\n\n```ts\n\u002F\u002F Option 2: postgres.js\nimport { drizzle } from \"drizzle-orm\u002Fpostgres-js\"\nimport postgres from \"postgres\"\nimport * as schema from \".\u002Fauth-schema\"\n\nconst client = postgres(process.env.DATABASE_URL!)\nexport const db = drizzle(client, { schema })\n```\n\n```ts\n\u002F\u002F Option 3: Neon serverless\nimport { drizzle } from \"drizzle-orm\u002Fneon-http\"\nimport { neon } from \"@neondatabase\u002Fserverless\"\nimport * as schema from \".\u002Fauth-schema\"\n\nconst sql = neon(process.env.DATABASE_URL!)\nexport const db = drizzle(sql, { schema })\n```\n\nThen pass to Better Auth:\n\n```ts\nimport { betterAuth } from \"better-auth\"\nimport { drizzleAdapter } from \"better-auth\u002Fadapters\u002Fdrizzle\"\nimport { db } from \".\u002Fdb\"\n\nexport const auth = betterAuth({\n  database: drizzleAdapter(db, { provider: \"pg\" }),\n  \u002F\u002F ...\n})\n```\n\n### Drizzle Config (`drizzle.config.ts`)\n\nRequired for `drizzle-kit` commands to find your schema:\n\n```ts\nimport { defineConfig } from \"drizzle-kit\"\n\nexport default defineConfig({\n  schema: \".\u002Fsrc\u002Fdb\u002Fauth-schema.ts\",\n  out: \".\u002Fdrizzle\",\n  dialect: \"postgresql\",\n  dbCredentials: {\n    url: process.env.DATABASE_URL!,\n  },\n})\n```\n\n---\n\n## Common Plugins\n\n| Plugin | Server Import | Client Import | Purpose |\n|--------|---------------|---------------|---------|\n| `twoFactor` | `better-auth\u002Fplugins` | `twoFactorClient` | 2FA with TOTP\u002FOTP |\n| `organization` | `better-auth\u002Fplugins` | `organizationClient` | Teams\u002Forgs |\n| `admin` | `better-auth\u002Fplugins` | `adminClient` | User management |\n| `bearer` | `better-auth\u002Fplugins` | - | API token auth |\n| `openAPI` | `better-auth\u002Fplugins` | - | API docs |\n| `passkey` | `@better-auth\u002Fpasskey` | `passkeyClient` | WebAuthn |\n| `sso` | `@better-auth\u002Fsso` | - | Enterprise SSO |\n\n**Plugin pattern:** Server plugin + client plugin + run migrations.\n\n---\n\n## Auth UI Implementation\n\n**Sign in flow:**\n1. `signIn.email({ email, password })` or `signIn.social({ provider, callbackURL })`\n2. Handle `error` in response\n3. Redirect on success\n\n**Session check (client):** `useSession()` hook returns `{ data: session, isPending }`\n\n**Session check (server):** `auth.api.getSession({ headers: await headers() })`\n\n**Protected routes:** Check session, redirect to `\u002Fsign-in` if null.\n\n---\n\n## Security Checklist\n\n- [ ] `BETTER_AUTH_SECRET` set (32+ chars)\n- [ ] `advanced.useSecureCookies: true` in production\n- [ ] `trustedOrigins` configured\n- [ ] Rate limits enabled\n- [ ] Email verification enabled\n- [ ] Password reset implemented\n- [ ] 2FA for sensitive apps\n- [ ] CSRF protection NOT disabled\n- [ ] `account.accountLinking` reviewed\n\n---\n\n## Troubleshooting\n\n| Issue | Fix |\n|-------|-----|\n| \"Secret not set\" | Add `BETTER_AUTH_SECRET` env var |\n| \"Invalid Origin\" | Add domain to `trustedOrigins` |\n| Cookies not setting | Check `baseURL` matches domain; enable secure cookies in prod |\n| OAuth callback errors | Verify redirect URIs in provider dashboard |\n| Type errors after adding plugin | Re-run CLI generate\u002Fmigrate |\n\n---\n\n## Resources\n\n- [Docs](https:\u002F\u002Fbetter-auth.com\u002Fdocs)\n- [Examples](https:\u002F\u002Fgithub.com\u002Fbetter-auth\u002Fexamples)\n- [Plugins](https:\u002F\u002Fbetter-auth.com\u002Fdocs\u002Fconcepts\u002Fplugins)\n- [CLI](https:\u002F\u002Fbetter-auth.com\u002Fdocs\u002Fconcepts\u002Fcli)\n- [Migration Guides](https:\u002F\u002Fbetter-auth.com\u002Fdocs\u002Fguides)\n","# Create Auth Skill\n\nGuide for adding authentication to TypeScript\u002FJavaScript applications using Better Auth.\n\n**For code examples and syntax, see [better-auth.com\u002Fdocs](https:\u002F\u002Fbetter-auth.com\u002Fdocs).**\n\n---\n\n## Phase 1: Planning (REQUIRED before implementation)\n\nBefore writing any code, gather requirements by scanning the project and asking the user structured questions. This ensures the implementation matches their needs.\n\n### Step 1: Scan the project\n\nAnalyze the codebase to auto-detect:\n- **Framework** — Look for `next.config`, `svelte.config`, `nuxt.config`, `astro.config`, `vite.config`, or Express\u002FHono entry files.\n- **Database\u002FORM** — Look for `prisma\u002Fschema.prisma`, `drizzle.config.ts`, `package.json` deps (`pg`, `postgres`, `@neondatabase\u002Fserverless`, `mysql2`, `better-sqlite3`, `mongoose`, `mongodb`). If `drizzle.config.ts` exists, read its `dialect` field to determine the DB type (e.g., `\"postgresql\"` → Drizzle + Postgres). Also check which Drizzle driver is installed (`drizzle-orm\u002Fnode-postgres` → `pg`, `drizzle-orm\u002Fpostgres-js` → `postgres`, `drizzle-orm\u002Fneon-http` → Neon).\n- **Existing auth** — Look for existing auth libraries (`next-auth`, `lucia`, `clerk`, `supabase\u002Fauth`, `firebase\u002Fauth`) in `package.json` or imports.\n- **Package manager** — Check for `pnpm-lock.yaml`, `yarn.lock`, `bun.lockb`, or `package-lock.json`.\n\nUse what you find to pre-fill defaults and skip questions you can already answer.\n\n### Step 2: Ask planning questions\n\nUse the `AskQuestion` tool to ask the user **all applicable questions in a single call**. Skip any question you already have a confident answer for from the scan. Group them under a title like \"Auth Setup Planning\".\n\n**Questions to ask:**\n\n1. **Project type** (skip if detected)\n   - Prompt: \"What type of project is this?\"\n   - Options: New project from scratch | Adding auth to existing project | Migrating from another auth library\n\n2. **Framework** (skip if detected)\n   - Prompt: \"Which framework are you using?\"\n   - Options: Next.js (App Router) | Next.js (Pages Router) | SvelteKit | Nuxt | Astro | Express | Hono | SolidStart | Other\n\n3. **Database & ORM** (skip if detected)\n   - Prompt: \"Which database setup will you use?\"\n   - Options: PostgreSQL (Prisma) | PostgreSQL (Drizzle) | PostgreSQL (pg driver) | MySQL (Prisma) | MySQL (Drizzle) | MySQL (mysql2 driver) | SQLite (Prisma) | SQLite (Drizzle) | SQLite (better-sqlite3 driver) | MongoDB (Mongoose) | MongoDB (native driver)\n\n4. **Authentication methods** (always ask, allow multiple)\n   - Prompt: \"Which sign-in methods do you need?\"\n   - Options: Email & password | Social OAuth (Google, GitHub, etc.) | Magic link (passwordless email) | Passkey (WebAuthn) | Phone number\n   - `allow_multiple: true`\n\n5. **Social providers** (only if they selected Social OAuth above — ask in a follow-up call)\n   - Prompt: \"Which social providers do you need?\"\n   - Options: Google | GitHub | Apple | Microsoft | Discord | Twitter\u002FX\n   - `allow_multiple: true`\n\n6. **Email verification** (only if Email & password was selected above — ask in a follow-up call)\n   - Prompt: \"Do you want to require email verification?\"\n   - Options: Yes | No\n\n7. **Email provider** (only if email verification is Yes, or if Password reset is selected in features — ask in a follow-up call)\n   - Prompt: \"How do you want to send emails?\"\n   - Options: Resend | Mock it for now (console.log)\n\n8. **Features & plugins** (always ask, allow multiple)\n   - Prompt: \"Which additional features do you need?\"\n   - Options: Two-factor authentication (2FA) | Organizations \u002F teams | Admin dashboard | API bearer tokens | Password reset | None of these\n   - `allow_multiple: true`\n\n9. **Auth pages** (always ask, allow multiple — pre-select based on earlier answers)\n   - Prompt: \"Which auth pages do you need?\"\n   - Options vary based on previous answers:\n     - Always available: Sign in | Sign up\n     - If Email & password selected: Forgot password | Reset password\n     - If email verification enabled: Email verification\n   - `allow_multiple: true`\n\n10. **Auth UI style** (always ask)\n   - Prompt: \"What style do you want for the auth pages? Pick one or describe your own.\"\n   - Options: Minimal & clean | Centered card with background | Split layout (form + hero image) | Floating \u002F glassmorphism | Other (I'll describe)\n\n### Step 3: Summarize the plan\n\nAfter collecting answers, present a concise implementation plan as a markdown checklist. Example:\n\n```\n## Auth Implementation Plan\n\n- **Framework:** Next.js (App Router)\n- **Database:** PostgreSQL via Prisma\n- **Auth methods:** Email\u002Fpassword, Google OAuth, GitHub OAuth\n- **Plugins:** 2FA, Organizations, Email verification\n- **UI:** Custom forms\n\n### Steps\n1. Install `better-auth` and `@better-auth\u002Fcli`\n2. Create `lib\u002Fauth.ts` with server config\n3. Create `lib\u002Fauth-client.ts` with React client\n4. Set up route handler at `app\u002Fapi\u002Fauth\u002F[...all]\u002Froute.ts`\n5. Configure Prisma adapter and generate schema\n6. Add Google & GitHub OAuth providers\n7. Enable `twoFactor` and `organization` plugins\n8. Set up email verification handler\n9. Run migrations\n10. Create sign-in \u002F sign-up pages\n```\n\nAsk the user to confirm the plan before proceeding to Phase 2.\n\n---\n\n## Phase 2: Implementation\n\nOnly proceed here after the user confirms the plan from Phase 1.\n\nFollow the decision tree below, guided by the answers collected above.\n\n```\nIs this a new\u002Fempty project?\n├─ YES → New project setup\n│   1. Install better-auth (+ scoped packages per plan)\n│   2. Create auth.ts with all planned config\n│   3. Create auth-client.ts with framework client\n│   4. Set up route handler\n│   5. Set up environment variables\n│   6. Run CLI migrate\u002Fgenerate\n│   7. Add plugins from plan\n│   8. Create auth UI pages\n│\n├─ MIGRATING → Migration from existing auth\n│   1. Audit current auth for gaps\n│   2. Plan incremental migration\n│   3. Install better-auth alongside existing auth\n│   4. Migrate routes, then session logic, then UI\n│   5. Remove old auth library\n│   6. See migration guides in docs\n│\n└─ ADDING → Add auth to existing project\n    1. Analyze project structure\n    2. Install better-auth\n    3. Create auth config matching plan\n    4. Add route handler\n    5. Run schema migrations\n    6. Integrate into existing pages\n    7. Add planned plugins and features\n```\n\nAt the end of implementation, guide users thoroughly on remaining next steps (e.g., setting up OAuth app credentials, deploying env vars, testing flows).\n\n---\n\n## Installation\n\n**Core:** `npm install better-auth`\n\n**Scoped packages (as needed):**\n| Package | Use case |\n|---------|----------|\n| `@better-auth\u002Fpasskey` | WebAuthn\u002FPasskey auth |\n| `@better-auth\u002Fsso` | SAML\u002FOIDC enterprise SSO |\n| `@better-auth\u002Fstripe` | Stripe payments |\n| `@better-auth\u002Fscim` | SCIM user provisioning |\n| `@better-auth\u002Fexpo` | React Native\u002FExpo |\n\n---\n\n## Environment Variables\n\n```env\nBETTER_AUTH_SECRET=\u003C32+ chars, generate with: openssl rand -base64 32>\nBETTER_AUTH_URL=http:\u002F\u002Flocalhost:3000\nDATABASE_URL=\u003Cyour database connection string>\n```\n\nAdd OAuth secrets as needed: `GITHUB_CLIENT_ID`, `GITHUB_CLIENT_SECRET`, `GOOGLE_CLIENT_ID`, etc.\n\n---\n\n## Server Config (auth.ts)\n\n**Location:** `lib\u002Fauth.ts` or `src\u002Flib\u002Fauth.ts`\n\n**Minimal config needs:**\n- `database` - Connection or adapter\n- `emailAndPassword: { enabled: true }` - For email\u002Fpassword auth\n\n**Standard config adds:**\n- `socialProviders` - OAuth providers (google, github, etc.)\n- `emailVerification.sendVerificationEmail` - Email verification handler\n- `emailAndPassword.sendResetPassword` - Password reset handler\n\n**Full config adds:**\n- `plugins` - Array of feature plugins\n- `session` - Expiry, cookie cache settings\n- `account.accountLinking` - Multi-provider linking\n- `rateLimit` - Rate limiting config\n\n**Export types:** `export type Session = typeof auth.$Infer.Session`\n\n---\n\n## Client Config (auth-client.ts)\n\n**Import by framework:**\n| Framework | Import |\n|-----------|--------|\n| React\u002FNext.js | `better-auth\u002Freact` |\n| Vue | `better-auth\u002Fvue` |\n| Svelte | `better-auth\u002Fsvelte` |\n| Solid | `better-auth\u002Fsolid` |\n| Vanilla JS | `better-auth\u002Fclient` |\n\n**Client plugins** go in `createAuthClient({ plugins: [...] })`.\n\n**Common exports:** `signIn`, `signUp`, `signOut`, `useSession`, `getSession`\n\n---\n\n## Route Handler Setup\n\n| Framework | File | Handler |\n|-----------|------|---------|\n| Next.js App Router | `app\u002Fapi\u002Fauth\u002F[...all]\u002Froute.ts` | `toNextJsHandler(auth)` → export `{ GET, POST }` |\n| Next.js Pages | `pages\u002Fapi\u002Fauth\u002F[...all].ts` | `toNextJsHandler(auth)` → default export |\n| Express | Any file | `app.all(\"\u002Fapi\u002Fauth\u002F*\", toNodeHandler(auth))` |\n| SvelteKit | `src\u002Fhooks.server.ts` | `svelteKitHandler(auth)` |\n| SolidStart | Route file | `solidStartHandler(auth)` |\n| Hono | Route file | `auth.handler(c.req.raw)` |\n\n**Next.js Server Components:** Add `nextCookies()` plugin to auth config.\n\n---\n\n## Database Migrations\n\n| Adapter | Command |\n|---------|---------|\n| Built-in Kysely | `npx @better-auth\u002Fcli@latest migrate` (applies directly) |\n| Prisma | `npx @better-auth\u002Fcli@latest generate --output prisma\u002Fschema.prisma` then `npx prisma migrate dev` |\n| Drizzle (dev) | `npx @better-auth\u002Fcli@latest generate --output src\u002Fdb\u002Fauth-schema.ts` then `npx drizzle-kit push` |\n| Drizzle (prod) | `npx @better-auth\u002Fcli@latest generate --output src\u002Fdb\u002Fauth-schema.ts` then `npx drizzle-kit generate` then `npx drizzle-kit migrate` |\n\n> **Note:** `drizzle-kit push` skips migration files and is only safe for development. Use `drizzle-kit generate` + `drizzle-kit migrate` in production.\n\n**Re-run after adding plugins.**\n\n---\n\n## Database Adapters\n\n| Database | Setup |\n|----------|-------|\n| SQLite | Pass `better-sqlite3` or `bun:sqlite` instance directly |\n| PostgreSQL | Pass `pg.Pool` instance directly |\n| MySQL | Pass `mysql2` pool directly |\n| Prisma | `prismaAdapter(prisma, { provider: \"postgresql\" })` from `better-auth\u002Fadapters\u002Fprisma` |\n| Drizzle (pg) | `drizzleAdapter(db, { provider: \"pg\" })` from `better-auth\u002Fadapters\u002Fdrizzle` |\n| Drizzle (mysql) | `drizzleAdapter(db, { provider: \"mysql\" })` from `better-auth\u002Fadapters\u002Fdrizzle` |\n| Drizzle (sqlite) | `drizzleAdapter(db, { provider: \"sqlite\" })` from `better-auth\u002Fadapters\u002Fdrizzle` |\n| MongoDB | `mongodbAdapter(db)` from `better-auth\u002Fadapters\u002Fmongodb` |\n\n### Drizzle + PostgreSQL Setup\n\nBefore using `drizzleAdapter`, initialize the `db` instance:\n\n```ts\n\u002F\u002F Option 1: node-postgres (pg)\nimport { drizzle } from \"drizzle-orm\u002Fnode-postgres\"\nimport { Pool } from \"pg\"\nimport * as schema from \".\u002Fauth-schema\"\n\nconst pool = new Pool({ connectionString: process.env.DATABASE_URL })\nexport const db = drizzle(pool, { schema })\n```\n\n```ts\n\u002F\u002F Option 2: postgres.js\nimport { drizzle } from \"drizzle-orm\u002Fpostgres-js\"\nimport postgres from \"postgres\"\nimport * as schema from \".\u002Fauth-schema\"\n\nconst client = postgres(process.env.DATABASE_URL!)\nexport const db = drizzle(client, { schema })\n```\n\n```ts\n\u002F\u002F Option 3: Neon serverless\nimport { drizzle } from \"drizzle-orm\u002Fneon-http\"\nimport { neon } from \"@neondatabase\u002Fserverless\"\nimport * as schema from \".\u002Fauth-schema\"\n\nconst sql = neon(process.env.DATABASE_URL!)\nexport const db = drizzle(sql, { schema })\n```\n\nThen pass to Better Auth:\n\n```ts\nimport { betterAuth } from \"better-auth\"\nimport { drizzleAdapter } from \"better-auth\u002Fadapters\u002Fdrizzle\"\nimport { db } from \".\u002Fdb\"\n\nexport const auth = betterAuth({\n  database: drizzleAdapter(db, { provider: \"pg\" }),\n  \u002F\u002F ...\n})\n```\n\n### Drizzle Config (`drizzle.config.ts`)\n\nRequired for `drizzle-kit` commands to find your schema:\n\n```ts\nimport { defineConfig } from \"drizzle-kit\"\n\nexport default defineConfig({\n  schema: \".\u002Fsrc\u002Fdb\u002Fauth-schema.ts\",\n  out: \".\u002Fdrizzle\",\n  dialect: \"postgresql\",\n  dbCredentials: {\n    url: process.env.DATABASE_URL!,\n  },\n})\n```\n\n---\n\n## Common Plugins\n\n| Plugin | Server Import | Client Import | Purpose |\n|--------|---------------|---------------|---------|\n| `twoFactor` | `better-auth\u002Fplugins` | `twoFactorClient` | 2FA with TOTP\u002FOTP |\n| `organization` | `better-auth\u002Fplugins` | `organizationClient` | Teams\u002Forgs |\n| `admin` | `better-auth\u002Fplugins` | `adminClient` | User management |\n| `bearer` | `better-auth\u002Fplugins` | - | API token auth |\n| `openAPI` | `better-auth\u002Fplugins` | - | API docs |\n| `passkey` | `@better-auth\u002Fpasskey` | `passkeyClient` | WebAuthn |\n| `sso` | `@better-auth\u002Fsso` | - | Enterprise SSO |\n\n**Plugin pattern:** Server plugin + client plugin + run migrations.\n\n---\n\n## Auth UI Implementation\n\n**Sign in flow:**\n1. `signIn.email({ email, password })` or `signIn.social({ provider, callbackURL })`\n2. Handle `error` in response\n3. Redirect on success\n\n**Session check (client):** `useSession()` hook returns `{ data: session, isPending }`\n\n**Session check (server):** `auth.api.getSession({ headers: await headers() })`\n\n**Protected routes:** Check session, redirect to `\u002Fsign-in` if null.\n\n---\n\n## Security Checklist\n\n- [ ] `BETTER_AUTH_SECRET` set (32+ chars)\n- [ ] `advanced.useSecureCookies: true` in production\n- [ ] `trustedOrigins` configured\n- [ ] Rate limits enabled\n- [ ] Email verification enabled\n- [ ] Password reset implemented\n- [ ] 2FA for sensitive apps\n- [ ] CSRF protection NOT disabled\n- [ ] `account.accountLinking` reviewed\n\n---\n\n## Troubleshooting\n\n| Issue | Fix |\n|-------|-----|\n| \"Secret not set\" | Add `BETTER_AUTH_SECRET` env var |\n| \"Invalid Origin\" | Add domain to `trustedOrigins` |\n| Cookies not setting | Check `baseURL` matches domain; enable secure cookies in prod |\n| OAuth callback errors | Verify redirect URIs in provider dashboard |\n| Type errors after adding plugin | Re-run CLI generate\u002Fmigrate |\n\n---\n\n## Resources\n\n- [Docs](https:\u002F\u002Fbetter-auth.com\u002Fdocs)\n- [Examples](https:\u002F\u002Fgithub.com\u002Fbetter-auth\u002Fexamples)\n- [Plugins](https:\u002F\u002Fbetter-auth.com\u002Fdocs\u002Fconcepts\u002Fplugins)\n- [CLI](https:\u002F\u002Fbetter-auth.com\u002Fdocs\u002Fconcepts\u002Fcli)\n- [Migration Guides](https:\u002F\u002Fbetter-auth.com\u002Fdocs\u002Fguides)\n",{"description":7},"main","58843b159d7a4050d6b785a98b908cce505c0b92","agent\u002Fskills\u002Fcreate-auth",0,"https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent","https:\u002F\u002Fgithub.com\u002FReihantt6","reihsns.web.id","2026-08-19 20:08:18",{"source":8,"skillName":5,"commands":33,"prompt":43,"zipAvailable":44},[34,37,40],{"tool":35,"command":36},"npx","npx skills add Reihantt6\u002Fsns-myagent --skill create-auth",{"tool":38,"command":39},"bunx","bunx skills add Reihantt6\u002Fsns-myagent --skill create-auth",{"tool":41,"command":42},"pnpm","pnpm dlx skills add Reihantt6\u002Fsns-myagent --skill create-auth","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent\u002Fblob\u002Fmain\u002Fagent\u002Fskills\u002Fcreate-auth\u002FSKILL.md",true,[],[47,54,61,68,75,82],{"skillNo":48,"name":49,"nameZh":6,"description":50,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":51,"categories":52,"keywords":53,"publishedAt":19},"01M77XDCYZ407XYMF2T4P6F7VT","youtube-transcript","Extract transcripts from YouTube videos. Use when the user asks for a transcript, subtitles, or captions of a YouTube video and provides a YouTube URL (youtube.com\u002Fwatch?v=, youtu.be\u002F, or similar). Supports output with or without timestamps.","https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent\u002Fblob\u002Fmain\u002Fagent\u002Fskills\u002Fyoutube-transcript\u002FSKILL.md",[],[],{"skillNo":55,"name":56,"nameZh":6,"description":57,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":58,"categories":59,"keywords":60,"publishedAt":19},"01M77XD7PBC98J6MXGJJ2TJ8DX","youtube-thumbnail-design","YouTube thumbnail design with specific dimensions, contrast rules, and mobile preview optimization. Covers safe zones, text placement, face expression psychology, and A\u002FB testing. Use for: YouTube thumbnails, video cover images, click-through optimization. Triggers: youtube thumbnail, thumbnail design, video thumbnail, click through rate, ctr optimization, youtube cover, video cover image, thumbnail maker, thumbnail tips, youtube design, video preview image","https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent\u002Fblob\u002Fmain\u002Fagent\u002Fskills\u002Fyoutube-thumbnail-design\u002FSKILL.md",[],[],{"skillNo":62,"name":63,"nameZh":6,"description":64,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":65,"categories":66,"keywords":67,"publishedAt":19},"01M77XD2541C8HXJ6RHYZP4NGJ","youtube-short-maker","Make YouTube Shorts that hold attention with Pexo — vertical 9:16, fast-paced, hook in the first 3 seconds. Describe your topic and Pexo writes the script, generates the shots, picks the models, and assembles a finished Short with music and captions. Use for YouTube Shorts: \"youtube short\", \"make a youtube short\", \"shorts video\", \"short-form video\". NOT for long-form or landscape video.","https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent\u002Fblob\u002Fmain\u002Fagent\u002Fskills\u002Fyoutube-short-maker\u002FSKILL.md",[],[],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":19},"01M77XCXKVSYK7KTZ3PQBVVGFD","xcode-project-setup","Safely modifies Xcode projects (.pbxproj) to add Swift Packages and link files. Use this skill whenever an iOS project needs dependencies installed (e.g. Firebase, Alamofire).","https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent\u002Fblob\u002Fmain\u002Fagent\u002Fskills\u002Fxcode-project-setup\u002FSKILL.md",[],[],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":19},"01M77XCR1DV8ZQK2NHWKVY4EWX","x402","Set up Browser Use Cloud payments with x402 — pay per request from a crypto wallet (USDC on Base mainnet), no signup or API key. Two setups it works out up front — \"just use it\" (set up a wallet so you or Claude Code can run cloud browser tasks paid from the wallet — Claude writes and runs throwaway scripts, nothing touches your codebase) or \"build it in\" (install the SDK and write the key + code into your project). Walks through wallet setup, funding, .env, and a ~$1 test run. Use when the user asks about x402, pay-per-use, USDC payments, or wants Browser Use Cloud without an API key. For the free-tier signup (reverse-CAPTCHA → API key), use `browser-use cloud signup` or the `cloud` skill instead.","https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent\u002Fblob\u002Fmain\u002Fagent\u002Fskills\u002Fx402\u002FSKILL.md",[],[],{"skillNo":83,"name":84,"nameZh":6,"description":85,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":19},"01M77XCMD3R3ZBZQQSW6E0793B","x-twitter-scraper","Build GitHub Copilot workflows with Xquik X API SDKs, REST endpoints, hosted Apify Actor runs, MCP tools, TweetClaw OpenClaw plugin installs, signed webhooks, tweet search, user lookup, follower exports, media actions, and agent automation.","https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent\u002Fblob\u002Fmain\u002Fagent\u002Fskills\u002Fx-twitter-scraper\u002FSKILL.md",[],[]]