用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/edfenton/claude-skills --skill mern-add-auth命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | mern-add-auth |
| description | Add authentication to a MERN project using NextAuth.js with OAuth and/or credentials. |
| argument-hint | [--providers google,github,credentials] [--with-user-model] |
| allowed-tools | Bash, Write, Read, Glob, Grep |
Add secure authentication to an existing MERN project using NextAuth.js (Auth.js).
--providers <list> — Comma-separated providers (default: google,github)
google, github, discord, credentials--with-user-model — Create User model in MongoDB for storing user dataapps/web/
├── app/api/auth/[...nextauth]/route.ts # NextAuth API route
├── src/lib/auth.ts # Auth config + providers
├── src/lib/auth-client.ts # Client-side helpers
├── src/components/auth/
│ ├── SignInButton.tsx # OAuth sign-in
│ ├── SignOutButton.tsx # Sign-out
│ └── UserMenu.tsx # User avatar + dropdown
├── src/server/db/models/user.ts # (if --with-user-model)
└── middleware.ts # Route protection
packages/shared/schemas/
└── user.ts # User schemas
.env.example # Updated with auth vars
# OAuth (per provider)
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=
# NextAuth
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET= # Generate with: openssl rand -base64 32
next-auth, @auth/mongodb-adapter (if using DB)Middleware protects routes matching these patterns by default:
/dashboard/*/settings/*/api/* (except /api/auth/* and /api/health)Customize in middleware.ts.
import { getServerSession } from 'next-auth';
import { authOptions } from '@/lib/auth';
const session = await getServerSession(authOptions);
if (!session) redirect('/api/auth/signin');
'use client';
import { useSession } from 'next-auth/react';
const { data: session, status } = useSession();
const session = await getServerSession(authOptions);
if (!session?.user?.id) {
return NextResponse.json(err('UNAUTHORIZED', 'Authentication required'), { status: 401 });
}
Summarize: providers configured, environment variables needed, protected routes, components available.
For templates and OAuth setup guides, see reference/mern-add-auth-reference.md