skill · from the nextjs-expert plugin
/add-auth
Add authentication to a Next.js application
- nextjs-expert plugin
- Slash command
you ›install the nextjs-expert plugin
metaphor ›Installed nextjs-expert. /add-auth is ready.
you ›/add-auth
metaphor ›Loaded the add-auth skill. What should I work on?
What the agent is told
This is the skill's SKILL.md, exactly what Metaphor reads before the task.
You are adding authentication to a Next.js application using Auth.js (NextAuth.js v5).
Workflow
Step 1: Assess Current State
Check if authentication already exists:
- Look for
auth.tsorauth.config.ts - Check for
next-authinpackage.json - Look for existing middleware
- Look for
Identify database setup:
- Check for Prisma schema
- Identify existing User model
Step 2: Ask About Requirements
Use AskUserQuestion to clarify:
- Providers: Which OAuth providers? (GitHub, Google, Email/Password)
- Session strategy: JWT or database sessions?
- Protected routes: Which routes need protection?
- Role-based access: Is RBAC needed?
Step 3: Install Dependencies
npm install next-auth@beta @auth/prisma-adapter
If using credentials:
npm install bcryptjs
npm install -D @types/bcryptjs
Step 4: Create Auth Configuration
Apply the auth-patterns skill and create:
auth.ts- Main auth configuration with:- Provider setup
- Adapter configuration
- Session callbacks
- JWT callbacks
app/api/auth/[...nextauth]/route.ts- Route handler
Step 5: Add Middleware
Create middleware.ts with:
- Route protection logic
- Redirect rules for auth pages
- Public route exceptions
Step 6: Update Database Schema
If using Prisma, add/update models:
- User
- Account
- Session
- VerificationToken
Step 7: Create Auth Components
- Login form - Credentials + OAuth buttons
- Register form - If using credentials
- User menu - Session-aware navigation
- Session provider - Client-side wrapper
Step 8: Environment Variables
Create/update .env.local:
AUTH_SECRET=generated-secret
AUTH_URL=http://localhost:3000
GITHUB_CLIENT_ID=...
GITHUB_CLIENT_SECRET=...
Implementation Checklist
- Install next-auth@beta
- Create auth.ts configuration
- Create API route handler
- Add middleware for route protection
- Update Prisma schema (if using database)
- Create login/register pages
- Add SessionProvider to layout
- Create auth-related components
- Set up environment variables
- Test authentication flow
Files to Create
| File | Purpose |
|---|---|
auth.ts |
Auth configuration |
app/api/auth/[...nextauth]/route.ts |
NextAuth route handler |
middleware.ts |
Route protection |
app/login/page.tsx |
Login page |
app/register/page.tsx |
Registration page (if credentials) |
components/login-form.tsx |
Login form component |
components/oauth-buttons.tsx |
OAuth sign-in buttons |
components/user-menu.tsx |
User dropdown menu |
app/providers.tsx |
SessionProvider wrapper |
types/next-auth.d.ts |
Extended types |
lib/auth-helpers.ts |
Auth utility functions |
Security Considerations
- Use
AUTH_SECRETfrom environment - Set
httpOnlycookies - Implement CSRF protection
- Hash passwords with bcrypt (min 12 rounds)
- Validate all inputs
- Rate limit authentication endpoints
Questions
What is the add-auth skill?
Add authentication to a Next.js application
How do I use add-auth in Metaphor?
Install the nextjs-expert plugin by asking the agent "install the nextjs-expert plugin", then type /add-auth in the composer.
What is a skill?
A skill is a set of written instructions the agent reads before it starts a kind of task. It changes how the agent works, not what it is allowed to do.
More from nextjs-expert
- /app-routerSkillThis skill should be used when the user asks to "create a Next.js route", "add a page", "set up layouts", "implement loading states", "add error boundaries"…in nextjs-expert
- /auth-patternsSkillThis skill should be used when the user asks about "authentication in Next.js", "NextAuth", "Auth.js", "middleware auth", "protected routes", "session…in nextjs-expert
- /optimizeSkillAnalyze and optimize Next.js application performancein nextjs-expert
- /route-handlersSkillThis skill should be used when the user asks to "create an API route", "add an endpoint", "build a REST API", "handle POST requests", "create route handlers"…in nextjs-expert
- /scaffoldSkillScaffold Next.js components following best practicesin nextjs-expert
- /server-actionsSkillThis skill should be used when the user asks about "Server Actions", "form handling in Next.js", "mutations", "useFormState", "useFormStatus"…in nextjs-expert