-
Notifications
You must be signed in to change notification settings - Fork 5
feat(agents): add technology stack subagents for modern web development #152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
56f0bd3
feat(agents): add technology stack subagents for modern web development
marcusquinn 42b14db
fix(agents): address code review feedback
marcusquinn d89d5ef
docs(ui): add scroll/overscroll debugging patterns from real session
marcusquinn a979055
fix(docs): address review comments - security, completeness, correctness
marcusquinn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,273 @@ | ||
| --- | ||
| description: Better Auth - authentication library for Next.js, sessions, OAuth | ||
| mode: subagent | ||
| tools: | ||
| read: true | ||
| write: true | ||
| edit: true | ||
| bash: true | ||
| glob: true | ||
| grep: true | ||
| webfetch: true | ||
| task: true | ||
| context7_*: true | ||
| --- | ||
|
|
||
| # Better Auth - Authentication Library | ||
|
|
||
| <!-- AI-CONTEXT-START --> | ||
|
|
||
| ## Quick Reference | ||
|
|
||
| - **Purpose**: Full-featured authentication for Next.js applications | ||
| - **Packages**: `better-auth`, `@better-auth/expo`, `@better-auth/passkey` | ||
| - **Docs**: Use Context7 MCP for current documentation | ||
|
|
||
| **Key Features**: | ||
| - Email/password, OAuth, magic links, passkeys | ||
| - Session management with database storage | ||
| - Built-in Drizzle adapter | ||
| - React hooks for client-side auth | ||
|
|
||
| **Server Setup**: | ||
|
|
||
| ```tsx | ||
| // packages/auth/src/server.ts | ||
| import { betterAuth } from "better-auth"; | ||
| import { drizzleAdapter } from "better-auth/adapters/drizzle"; | ||
| import { db } from "@workspace/db"; | ||
|
|
||
| // Validate required environment variables | ||
| const requiredEnvVars = ['GOOGLE_CLIENT_ID', 'GOOGLE_CLIENT_SECRET', 'BETTER_AUTH_SECRET'] as const; | ||
| for (const envVar of requiredEnvVars) { | ||
| if (!process.env[envVar]) { | ||
| throw new Error(`Missing required environment variable: ${envVar}`); | ||
| } | ||
| } | ||
|
|
||
| export const auth = betterAuth({ | ||
| database: drizzleAdapter(db, { | ||
| provider: "pg", | ||
| }), | ||
| emailAndPassword: { | ||
| enabled: true, | ||
| }, | ||
| socialProviders: { | ||
| google: { | ||
| clientId: process.env.GOOGLE_CLIENT_ID, | ||
| clientSecret: process.env.GOOGLE_CLIENT_SECRET, | ||
| }, | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| **Client Hooks**: | ||
|
|
||
| ```tsx | ||
| // packages/auth/src/client/react.ts | ||
| import { createAuthClient } from "better-auth/react"; | ||
|
|
||
| export const authClient = createAuthClient({ | ||
| baseURL: process.env.NEXT_PUBLIC_APP_URL, | ||
| }); | ||
|
|
||
| export const { useSession, signIn, signOut, signUp } = authClient; | ||
| ``` | ||
|
|
||
| **Usage in Components**: | ||
|
|
||
| ```tsx | ||
| "use client"; | ||
| import { useSession, signIn, signOut } from "@workspace/auth/client/react"; | ||
|
|
||
| function AuthButton() { | ||
| const { data: session, isPending } = useSession(); | ||
|
|
||
| if (isPending) return <div>Loading...</div>; | ||
|
|
||
| if (session) { | ||
| return ( | ||
| <div> | ||
| <span>{session.user.email}</span> | ||
| <button onClick={() => signOut()}>Sign Out</button> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| // Get from form state | ||
| const { email, password } = formData; | ||
| <button onClick={() => signIn.email({ email, password })}> | ||
| Sign In | ||
| </button> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| **Protected Routes**: | ||
|
|
||
| ```tsx | ||
| // middleware.ts | ||
| import { auth } from "@workspace/auth/server"; | ||
|
|
||
| export default auth.middleware({ | ||
| publicRoutes: ["/", "/login", "/signup"], | ||
| redirectTo: "/login", | ||
| }); | ||
| ``` | ||
|
|
||
| <!-- AI-CONTEXT-END --> | ||
|
|
||
| ## Detailed Patterns | ||
|
|
||
| ### OAuth Sign In | ||
|
|
||
| ```tsx | ||
| import { signIn } from "@workspace/auth/client/react"; | ||
|
|
||
| // Google OAuth | ||
| <button onClick={() => signIn.social({ provider: "google" })}> | ||
| Sign in with Google | ||
| </button> | ||
|
|
||
| // GitHub OAuth | ||
| <button onClick={() => signIn.social({ provider: "github" })}> | ||
| Sign in with GitHub | ||
| </button> | ||
| ``` | ||
|
|
||
| ### Email/Password Sign Up | ||
|
|
||
| ```tsx | ||
| import { signUp } from "@workspace/auth/client/react"; | ||
|
|
||
| const handleSignUp = async (data: { email: string; password: string; name: string }) => { | ||
| const result = await signUp.email({ | ||
| email: data.email, | ||
| password: data.password, | ||
| name: data.name, | ||
| }); | ||
|
|
||
| if (result.error) { | ||
| console.error(result.error); | ||
| return; | ||
| } | ||
|
|
||
| // User created and signed in | ||
| router.push("/dashboard"); | ||
| }; | ||
| ``` | ||
|
|
||
| ### Server-Side Session | ||
|
|
||
| ```tsx | ||
| // In server component or API route | ||
| import { auth } from "@workspace/auth/server"; | ||
| import { headers } from "next/headers"; | ||
|
|
||
| export async function getServerSession() { | ||
| const session = await auth.api.getSession({ | ||
| headers: await headers(), | ||
| }); | ||
| return session; | ||
| } | ||
|
|
||
| // Usage in page | ||
| import { redirect } from "next/navigation"; | ||
|
|
||
| export default async function DashboardPage() { | ||
| const session = await getServerSession(); | ||
|
|
||
| if (!session) { | ||
| redirect("/login"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| return <div>Welcome, {session.user.name}</div>; | ||
| } | ||
| ``` | ||
|
|
||
| ### Passkey Authentication | ||
|
|
||
| ```tsx | ||
| // Server config | ||
| import { passkey } from "@better-auth/passkey"; | ||
|
|
||
| export const auth = betterAuth({ | ||
| plugins: [passkey()], | ||
| // ... other config | ||
| }); | ||
|
|
||
| // Client usage | ||
| import { signIn } from "@workspace/auth/client/react"; | ||
|
|
||
| <button onClick={() => signIn.passkey()}> | ||
| Sign in with Passkey | ||
| </button> | ||
| ``` | ||
|
|
||
| ### Custom Session Data | ||
|
|
||
| ```tsx | ||
| // Extend session with custom fields | ||
| export const auth = betterAuth({ | ||
| session: { | ||
| expiresIn: 60 * 60 * 24 * 7, // 7 days | ||
| updateAge: 60 * 60 * 24, // Update session every 24 hours | ||
| cookieCache: { | ||
| enabled: true, | ||
| maxAge: 60 * 5, // 5 minutes | ||
| }, | ||
| }, | ||
| user: { | ||
| additionalFields: { | ||
| role: { | ||
| type: "string", | ||
| defaultValue: "user", | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| ### Database Schema Generation | ||
|
|
||
| ```bash | ||
| # Generate auth schema for Drizzle | ||
| pnpm --filter auth db:generate | ||
|
|
||
| # This creates/updates packages/db/src/schema/auth.ts | ||
| ``` | ||
|
|
||
| ### API Route Handler | ||
|
|
||
| ```tsx | ||
| // app/api/auth/[...all]/route.ts | ||
| import { auth } from "@workspace/auth/server"; | ||
| import { toNextJsHandler } from "better-auth/next-js"; | ||
|
|
||
| export const { GET, POST } = toNextJsHandler(auth); | ||
| ``` | ||
|
|
||
| ## Common Mistakes | ||
|
|
||
| 1. **Missing environment variables** | ||
| - `BETTER_AUTH_SECRET` required | ||
| - OAuth credentials for each provider | ||
|
|
||
| 2. **Not generating schema** | ||
| - Run `db:generate` after auth config changes | ||
| - Auth tables must exist in database | ||
|
|
||
| 3. **Forgetting to await headers()** | ||
| - `headers()` is async in Next.js 15+ | ||
| - Always `await headers()` before passing to auth | ||
|
|
||
| 4. **Client/server import confusion** | ||
| - Use `@workspace/auth/server` on server | ||
| - Use `@workspace/auth/client/react` on client | ||
|
|
||
| ## Related | ||
|
|
||
| - `tools/api/drizzle.md` - Database adapter | ||
| - `tools/ui/nextjs-layouts.md` - Protected layouts | ||
| - Context7 MCP for Better Auth documentation | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
emailandpasswordvariables used insignIn.email({ email, password })are not defined within theAuthButtoncomponent snippet. This could be confusing for developers trying to use this example. To make it clearer, consider showing how these values would typically be managed, for instance, by retrieving them from a form's state.