adding-auth — Claude Code skill: Next.js auth with Auth.js
A skill that walks the agent through adding authentication to a web app with NextAuth.js: OAuth providers, sessions and protected routes.
npx skills add spencerpauly/awesome-cursor-skills --skill adding-auth -a claude-codeWhat adding-auth does
The skill kicks in when you ask the agent to add login, sign-up, OAuth or session handling. From there it works through the steps: installs next-auth@beta, generates a secret with npx auth secret and writes AUTH_SECRET to .env.local, creates auth.ts in the project root with GitHub and Google providers, and adds the route handler at app/api/auth/[...nextauth]/route.ts.
Sign-in and sign-out UI comes next: components call the signIn and signOut server actions, or a link points at /api/auth/signin. Route protection uses the auth() function in server components or middleware, and a page without a session redirects to sign-in. If you need persistent sessions or user records, the skill suggests a database adapter such as @auth/drizzle-adapter or @auth/prisma-adapter.
You need provider keys up front: AUTH_GITHUB_ID, AUTH_GITHUB_SECRET, AUTH_GOOGLE_ID, AUTH_GOOGLE_SECRET. For production the skill reminds you to add NEXTAUTH_URL — skip it and sign-in breaks on your live domain. Auth.js v5 targets the App Router and server actions; the Pages Router path is different, using getServerSession in getServerSideProps and useSession on the client.
What it helps with
- add GitHub and Google sign-in to a Next.js app
- generate
AUTH_SECRETand wire up the env vars - block guests from a page with
auth()in a server component - hook up a database adapter for persistent sessions
- move auth to the Pages Router with
getServerSession
Example prompts for the agent
- add authentication to this project with Auth.js
- set up GitHub and Google login and protect /dashboard
- build sign-up and sign-out, keep the session in the database
How to install adding-auth
1Skills CLI (Vercel)
npx skills add spencerpauly/awesome-cursor-skills --skill adding-auth -a claude-code2Manually: put the files in place
~/.claude/skills/adding-auth/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/adding-auth/
1Skills CLI (Vercel)
npx skills add spencerpauly/awesome-cursor-skills --skill adding-auth -a codex2Manually: put the files in place
.agents/skills/adding-auth/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add spencerpauly/awesome-cursor-skills --skill adding-auth -a cursor2Manually: put the files in place
.cursor/skills/adding-auth/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install spencerpauly/awesome-cursor-skills adding-auth2Manually: put the files in place
.github/skills/adding-auth/SKILL.md1Skills CLI (Vercel)
npx skills add spencerpauly/awesome-cursor-skills --skill adding-auth -a gemini-cli2Platform CLI
gemini skills install https://github.com/spencerpauly/awesome-cursor-skills --path resources/adding-authManually: put the files in place
.devin/skills/adding-auth/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add spencerpauly/awesome-cursor-skills --skill adding-auth -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about adding-auth
How do I install adding-auth in Claude?
Run npx skills add spencerpauly/awesome-cursor-skills --skill adding-auth -a claude-code. The skill file lands at ~/.claude/skills/adding-auth/SKILL.md.
What does adding-auth do?
It walks the agent through adding NextAuth.js authentication: package install, secret generation, the auth.ts config, the route handler, sign-in UI and route protection.
Does it work with the Pages Router?
Yes, but the pattern differs: use getServerSession in getServerSideProps and useSession on the client instead of auth() in server components.
Source text
SKILL.md · CC0-1.0
---
name: adding-auth
description: Add authentication to a web application using NextAuth.js (Auth.js), including OAuth providers, session management, and protected routes.
---
# Add Authentication (Auth.js)
Use this skill when the user asks to add authentication, login, sign-up, OAuth, or session management.
## Steps
1. **Install dependencies**
```bash
npm install next-auth@beta
```
2. **Generate an auth secret**
```bash
npx auth secret
```
This adds `AUTH_SECRET` to `.env.local`.
3. **Create the auth config** — create `auth.ts` in the project root:
```ts
import NextAuth from "next-auth";
import GitHub from "next-auth/providers/github";
import Google from "next-auth/providers/google";
export const { handlers, signIn, signOut, auth } = NextAuth({
providers: [GitHub, Google],
});
```
4. **Add the route handler** — create `app/api/auth/[...nextauth]/route.ts`:
```ts
import { handlers } from "@/auth";
export const { GET, POST } = handlers;
```
5. **Add environment variables** for each provider:
```
AUTH_SECRET=...
AUTH_GITHUB_ID=...
AUTH_GITHUB_SECRET=...
AUTH_GOOGLE_ID=...
AUTH_GOOGLE_SECRET=...
```
6. **Add sign-in/sign-out UI** — create components that call the `signIn` and `signOut` server actions, or use `<Link href="/api/auth/signin">`.
7. **Protect routes** — use the `auth()` function in server components or middleware:
```ts
import { auth } from "@/auth";
export default async function ProtectedPage() {
const session = await auth();
if (!session) redirect("/api/auth/signin");
return <div>Welcome {session.user?.name}</div>;
}
```
8. **Add database adapter (optional)** — if the user needs persistent sessions or user records, install a database adapter (e.g. `@auth/drizzle-adapter`, `@auth/prisma-adapter`) and configure it in the auth config.
## Notes
- Auth.js v5 works with Next.js App Router and Server Actions natively.
- For Pages Router, use `getServerSession` in `getServerSideProps` and `useSession` on the client.
- Add `NEXTAUTH_URL` for production deployments.
- Store minimal user data in the session; fetch full profiles from the database when needed.
© spencerpauly · CC0-1.0 · spencerpauly/awesome-cursor-skills