원클릭으로
auth-pages
// Create and manage authentication pages with server-side session handling. Use when adding login, register, or protected pages WITHOUT flicker/skeleton.
// Create and manage authentication pages with server-side session handling. Use when adding login, register, or protected pages WITHOUT flicker/skeleton.
Generate TypeScript API client from Swagger/Go comments. Use when updating API endpoints, adding new routes, or regenerating the frontend API client after backend changes.
Manage database migrations and Better Auth schema. Use when adding tables, modifying schema, running migrations, or resetting the database.
Generate full-stack features. Backend = hand-written bounded-context aggregates (DDD); frontend = FSD slices with HydrationBoundary. Use when creating new features, adding CRUD operations, or scaffolding new pages.
Access local technical documentation before searching the internet. Use FIRST when researching any tech stack question.
Server-Side + Client-Side Data Fetching with Orval + TanStack Query HydrationBoundary Pattern. ALWAYS use Orval - NEVER manual fetch()!
Feature-Sliced Design architecture for frontend. Use when creating new features, slices, or understanding the FSD layer structure.
| name | auth-pages |
| description | Create and manage authentication pages with server-side session handling. Use when adding login, register, or protected pages WITHOUT flicker/skeleton. |
| allowed-tools | Read, Edit, Write, Glob |
Better Auth integration with Next.js 16 - Magic Link (passwordless) authentication.
This project uses Magic Link authentication - users sign in by clicking a link sent to their email. No passwords!
src/
├── app/(auth)/
│ ├── login/ # Magic Link Login Page
│ ├── magic-link/verify/ # Magic Link Verification UI
│ └── verify-email/ # Email Verification UI
├── app/(protected)/
│ ├── dashboard/ # Protected Dashboard
│ └── settings/ # Session Management
├── features/auth/ # Auth Feature
│ ├── ui/
│ │ ├── login-form.tsx # Orchestrates login flow
│ │ ├── login-card.tsx # Email input form
│ │ └── email-sent-card.tsx # "Check your email" UI
│ ├── model/
│ │ ├── use-login.ts # Login state & logic
│ │ └── use-auth-sync.ts # Cross-tab sync
│ └── index.ts
├── features/user-settings/ # Session Management
│ ├── ui/
│ │ ├── sessions-list.tsx
│ │ └── session-card.tsx
│ ├── model/
│ │ └── use-sessions.ts
│ └── index.ts
├── shared/lib/
│ ├── auth-client/ # Client: signIn.magicLink, signOut
│ ├── auth-server/ # Server: getSession, auth config
│ └── geo/ # User Agent parsing
└── widgets/header/ # Header with UserMenu
1. User enters email → /login
2. signIn.magicLink() called
3. Backend webhook sends email
4. User clicks link → /magic-link/verify?token=...
5. Token verified → Session created → Redirect to /dashboard
6. Login notification sent (new device only)
import { signIn, signOut } from "@shared/lib/auth-client"
// Request Magic Link
await signIn.magicLink({
email,
callbackURL: "/dashboard",
newUserCallbackURL: "/dashboard",
errorCallbackURL: "/login?error=verification_failed",
})
// Sign Out
await signOut()
// app/(protected)/dashboard/page.tsx - SERVER COMPONENT
import { getSession } from "@shared/lib/auth-server"
import { redirect } from "next/navigation"
import { Header } from "@widgets/header"
export default async function DashboardPage() {
// Server-side Session Check - NO Flicker!
const session = await getSession()
if (!session) redirect("/login")
return (
<div className="min-h-screen bg-background">
<Header user={session.user} />
{/* Content */}
</div>
)
}
Users can view and revoke sessions at /settings:
import { useSessions } from "@features/user-settings"
export function SessionsList() {
const { sessions, revokeSession, revokeOtherSessions } = useSessions()
return (
<div>
{sessions.map((session) => (
<SessionCard
key={session.id}
session={session}
onRevoke={revokeSession}
/>
))}
<Button onClick={revokeOtherSessions}>
Alle anderen Sessions beenden
</Button>
</div>
)
}
All emails are sent by the Go backend (Clean Architecture):
POST /api/v1/webhooks/send-magic-link
POST /api/v1/webhooks/send-verification-email
POST /api/v1/webhooks/session-created
Protected by X-Webhook-Secret header.
// features/auth/model/use-auth-sync.ts
import { useAuthSync, broadcastSignOut } from "@features/auth"
// In Header component
useAuthSync() // Listen for auth changes
// On sign out
await signOut()
await broadcastSignOut() // Notify other tabs
Custom UI for /magic-link/verify:
Email sent on new device/IP:
/settings❌ DO NOT use useSession() in Protected Pages → Causes flicker
❌ DO NOT use password fields → Magic Link only
❌ DO NOT send emails from frontend → Use backend webhooks
❌ DO NOT use direct SQL in auth hooks → Use webhooks
✅ INSTEAD:
getSession()redirect() if no session