用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/tools-only/X-Skills --skill auth-setup命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Index of Build Systems Skills
Coordination patterns for distributed dataflow systems including barriers, epochs, and distributed snapshots
Windowing, sessionization, time-series aggregation, and late data handling for streaming systems
基于 SOC 职业分类
正在显示 SKILL.md
| name | auth-setup |
| description | Generate authentication boilerplate with JWT, OAuth, and session support |
| shortcut | as |
| category | backend |
| difficulty | intermediate |
| estimated_time | 5-10 minutes |
Generates complete authentication boilerplate including JWT, OAuth (Google/GitHub), session management, and password reset flows.
Generated Auth System:
Output: Complete authentication system ready for production
Time: 5-10 minutes
# Generate full auth system
/auth-setup jwt
# Shortcut
/as oauth --providers google,github
# With specific features
/as jwt --features email-verification,password-reset,2fa
auth.service.ts:
import bcrypt from 'bcrypt'
import jwt from 'jsonwebtoken'
import { User } from './models/User'
export class AuthService {
async register(email: string, password: string, name: string) {
// Check if user exists
const existing = await User.findOne({ email })
if (existing) {
throw new Error('Email already registered')
}
// Hash password
const hashedPassword = await bcrypt.hash(password, 12)
// Create user
const user = await User.create({
email,
password: hashedPassword,
name,
emailVerified: false
})
// Generate verification token
const verificationToken = this.generateToken({ userId: user.id, : }, )
.(email, verificationToken)
accessToken = .(user)
refreshToken = .(user)
{
: { : user., : user., : user. },
accessToken,
refreshToken
}
}
() {
user = .({ email })
(!user) {
()
}
validPassword = bcrypt.(password, user.)
(!validPassword) {
()
}
(!user.) {
()
}
accessToken = .(user)
refreshToken = .(user)
{
: { : user., : user., : user. },
accessToken,
refreshToken
}
}
() {
{
decoded = jwt.(refreshToken, process..!)
user = .(decoded.)
(!user) {
()
}
accessToken = .(user)
{ accessToken }
} (error) {
()
}
}
() {
decoded = jwt.(token, process..!)
(decoded. !== ) {
()
}
.(decoded., { : })
{ : }
}
() {
user = .({ email })
(!user) {
{ : }
}
resetToken = .({ : user., : }, )
.(email, resetToken)
{ : }
}
() {
decoded = jwt.(token, process..!)
(decoded. !== ) {
()
}
hashedPassword = bcrypt.(newPassword, )
.(decoded., { : hashedPassword })
{ : }
}
() {
jwt.(
{ : user., : user. },
process..!,
{ : }
)
}
() {
jwt.(
{ : user. },
process..!,
{ : }
)
}
() {
jwt.(payload, process..!, { expiresIn })
}
() {
}
() {
}
}
oauth.controller.ts:
import { OAuth2Client } from 'google-auth-library'
const googleClient = new OAuth2Client(
process.env.GOOGLE_CLIENT_ID,
process.env.GOOGLE_CLIENT_SECRET,
process.env.GOOGLE_REDIRECT_URI
)
export class OAuthController {
async googleLogin(req: Request, res: Response) {
const authUrl = googleClient.generateAuthUrl({
access_type: 'offline',
scope: ['profile', 'email']
})
res.redirect(authUrl)
}
async googleCallback(req: Request, res: Response) {
const { code } = req.query
const { tokens } = await googleClient.getToken(code as string)
googleClient.setCredentials(tokens)
const ticket = await googleClient.verifyIdToken({
idToken: tokens.!,
: process..
})
payload = ticket.()
(!payload) {
()
}
user = .({ : payload. })
(!user) {
user = .({
: payload.,
: payload.,
: payload.,
: ,
: ,
: payload.
})
}
accessToken = (user)
refreshToken = (user)
res.()
}
}
auth.middleware.ts:
import { Request, Response, NextFunction } from 'express'
import jwt from 'jsonwebtoken'
declare global {
namespace Express {
interface Request {
user?: {
userId: string
email: string
}
}
}
}
export async function authenticate(req: Request, res: Response, next: NextFunction) {
try {
const authHeader = req.headers.authorization
if (!authHeader?.startsWith('Bearer ')) {
return res.status(401).json({ error: 'No token provided' })
}
const token = authHeader.split(' ')[1]
const decoded = jwt.verify(token, process.env.JWT_SECRET!)
req. = {
: decoded.,
: decoded.
}
()
} (error) {
(error jwt.) {
res.().({ : })
}
res.().({ : })
}
}
() {
(: , : , : ) => {
(!req.) {
res.().({ : })
}
user = .(req..)
(!user || !roles.(user.)) {
res.().({ : })
}
()
}
}
import rateLimit from 'express-rate-limit'
export const authLimiter = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 5, // 5 requests per window
message: 'Too many login attempts, please try again later',
standardHeaders: true,
legacyHeaders: false
})
// Usage
app.post('/api/auth/login', authLimiter, authController.login)
# JWT
JWT_SECRET=your-super-secret-key-min-32-chars
JWT_REFRESH_SECRET=your-refresh-secret-key
JWT_EXPIRES_IN=15m
JWT_REFRESH_EXPIRES_IN=7d
# OAuth - Google
GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=your-client-secret
GOOGLE_REDIRECT_URI=http://localhost:3000/api/auth/google/callback
# OAuth - GitHub
GITHUB_CLIENT_ID=your-github-client-id
GITHUB_CLIENT_SECRET=your-github-client-secret
GITHUB_REDIRECT_URI=http://localhost:3000/api/auth/github/callback
# Email
SMTP_HOST=smtp.sendgrid.net
SMTP_PORT=587
SMTP_USER=apikey
SMTP_PASSWORD=your-sendgrid-api-key
FROM_EMAIL=[email protected]
// routes/auth.routes.ts
import { Router } from 'express'
import { AuthController } from '../controllers/auth.controller'
import { authenticate } from '../middleware/auth.middleware'
import { authLimiter } from '../middleware/rate-limit'
const router = Router()
const authController = new AuthController()
// Registration & Login
router.post('/register', authController.register)
router.post('/login', authLimiter, authController.login)
router.post('/refresh', authController.refreshToken)
router.post('/logout', authenticate, authController.logout)
// Email Verification
router.post('/verify-email', authController.verifyEmail)
router.post('/resend-verification', authController.resendVerification)
// Password Reset
router.post('/forgot-password', authLimiter, authController.forgotPassword)
router.post('/reset-password', authController.resetPassword)
router.(, authController.)
router.(, authController.)
router.(, authController.)
router.(, authController.)
router.(, authenticate, authController.)
router.(, authenticate, authController.)
router.(, authenticate, authController.)
router
/env-config-setup - Generate environment config/express-api-scaffold - Generate Express API/fastapi-scaffold - Generate FastAPISecure authentication. Easy integration. Production-ready.