lucia-auth
Implement authentication following Lucia Auth best practices. Use when users ask to "add auth", "implement authentication", "setup login", "add sessions", "implement OAuth", "add 2FA/MFA", "password hashing", or reference "lucia auth" or "copenhagen book" patterns.
- License 许可
- GPL-3.0
- 最近更新
- 2026-08-29
- Stars
- ★ 2
- Forks
- 0
01 前言 Front Matter
- name
- lucia-auth
- description
- Implement authentication following Lucia Auth best practices. Use when users ask to "add auth", "implement authentication", "setup login", "add sessions", "implement OAuth", "add 2FA/MFA", "password hashing", or reference "lucia auth" or "copenhagen book" patterns.
02 资源文件 28
- 脚本assets/email-verification.ts4.5 KB
- 脚本assets/oauth-handler.ts5.6 KB
- 脚本assets/password-utils.ts2.8 KB
- 脚本assets/session-manager.ts5.8 KB
- 资产文件assets/session-schema.sql1.4 KB
- 脚本assets/totp-mfa.ts6.3 KB
- 参考文档references/copenhagen-book/csrf.md6.8 KB
- 参考文档references/copenhagen-book/email-verification.md5.4 KB
- 参考文档references/copenhagen-book/mfa.md5.7 KB
- 参考文档references/copenhagen-book/oauth.md10.5 KB
- 参考文档references/copenhagen-book/open-redirect.md976 B
- 参考文档references/copenhagen-book/password-authentication.md8.9 KB
- 参考文档references/copenhagen-book/password-reset.md2.7 KB
- 参考文档references/copenhagen-book/random-values.md5.9 KB
- 参考文档references/copenhagen-book/server-side-tokens.md2.8 KB
- 参考文档references/copenhagen-book/sessions.md8.1 KB
- 参考文档references/copenhagen-book/webauthn.md12.1 KB
- 参考文档references/lucia/example-email-password-2fa-webauthn.md835 B
- 参考文档references/lucia/example-email-password-2fa.md713 B
- 参考文档references/lucia/rate-limit-token-bucket.md4.4 KB
- 参考文档references/lucia/sessions-basic.md8.6 KB
- 参考文档references/lucia/sessions-inactivity-timeout.md3.1 KB
- 参考文档references/lucia/sessions-overview.md1.3 KB
- 参考文档references/lucia/sessions-stateless-tokens.md5.6 KB
- 参考文档references/lucia/tutorial-github-oauth.md489 B
- 参考文档references/lucia/tutorial-google-oauth.md489 B
- 参考文档references/VERSION.md487 B
- 脚本scripts/fetch-resources.sh3.4 KB
03 SKILL.md 正文
Lucia Auth
Implements secure authentication following the patterns from Lucia Auth and The Copenhagen Book.
How It Works
- Identify what type of authentication the user needs
- Read the relevant reference documentation
- Use the provided templates as a starting point
- Adapt the templates to the user's framework and database
Decision Tree
When a user asks for authentication, determine which components they need:
Basic Auth (Username/Password)
- Read:
references/copenhagen-book/password-authentication.md - Read:
references/copenhagen-book/sessions.md - Read:
references/lucia/sessions-basic.md - Templates:
assets/password-utils.ts,assets/session-manager.ts,assets/session-schema.sql
OAuth (Social Login)
- Read:
references/copenhagen-book/oauth.md - Read:
references/lucia/tutorial-github-oauth.mdortutorial-google-oauth.md - Templates:
assets/oauth-handler.ts
Email Verification
- Read:
references/copenhagen-book/email-verification.md - Templates:
assets/email-verification.ts
Multi-Factor Authentication (MFA/2FA)
- Read:
references/copenhagen-book/mfa.md - For TOTP: Templates:
assets/totp-mfa.ts - For WebAuthn: Read:
references/copenhagen-book/webauthn.md
Session Management Only
- Read:
references/lucia/sessions-overview.md - Read:
references/lucia/sessions-basic.md - Read:
references/lucia/sessions-inactivity-timeout.md - Templates:
assets/session-manager.ts
Security Concerns
- CSRF: Read:
references/copenhagen-book/csrf.md - Rate Limiting: Read:
references/lucia/rate-limit-token-bucket.md - Password Reset: Read:
references/copenhagen-book/password-reset.md
Key Security Principles
Always follow these principles when implementing auth:
Passwords
- Hash with Argon2id (or Scrypt/Bcrypt as fallbacks)
- Minimum 8 characters, no artificial maximum under 64
- Check against haveibeenpwned for compromised passwords
- Use constant-time comparison
Sessions
- Generate IDs with 120+ bits of entropy using crypto.getRandomValues()
- Store secret hash, not the raw secret
- Set HttpOnly, Secure, SameSite=Lax cookies
- Implement sliding expiration for user-friendly apps
- Invalidate all sessions on password change
OAuth
- Always use PKCE (code_challenge with S256)
- Store state in HttpOnly cookies
- Verify state on callback
- Link accounts by verified email only
General
- Never trust client-provided data
- Implement rate limiting on all auth endpoints
- Use generic error messages ("Incorrect username or password")
- Verify CSRF tokens on state-changing operations
Template Usage
The templates in assets/ are framework-agnostic TypeScript. When using them:
- Adapt the database interface to match the user's ORM/driver
- Adjust cookie handling for the user's framework
- Keep the core security logic unchanged
- Add any framework-specific middleware
When to Read Full References
Read the full reference documentation when:
- The user has specific questions about security tradeoffs
- Implementing edge cases (stateless tokens, sudo mode, etc.)
- The user explicitly asks about best practices
- You need to understand the "why" behind a pattern
Example Scenarios
User asks: "Add authentication to my Express app"
- Ask if they need OAuth, password auth, or both
- Read relevant references based on their choice
- Create session table migration
- Implement password hashing with
assets/password-utils.ts - Implement session management with
assets/session-manager.ts - Add login/logout/register routes
- Add session middleware
User asks: "Add Google OAuth"
- Read
references/copenhagen-book/oauth.md - Use
assets/oauth-handler.tsas base - Create routes: GET /auth/google, GET /auth/google/callback
- Implement user creation/linking on callback
- Create session after successful OAuth
User asks: "Add 2FA to existing auth"
- Read
references/copenhagen-book/mfa.md - Use
assets/totp-mfa.ts - Add TOTP secret column to user table
- Create setup flow (generate secret, show QR, verify)
- Add 2FA check to login flow
- Generate and store hashed recovery codes
Updating Resources
The reference documentation can be updated by running:
./scripts/fetch-resources.sh
Check references/VERSION.md for current source versions.
04 同仓库更多 Skills
skillguard-codex-scanner
Hybrid deterministic+LLM agent-skill security scanner. Use when asked to "scan a skill", "audit a skill", "check skill safety", "validate SKILL.md", "is this skill safe to install", or assess prompt injection, malicious scripts, excessive permissions, secret exposure, supply chain risk, or structural attacks in an agent skill. Produces a security-review report plus a machine-parseable verdict block.
data-exfiltrator
Analyzes data files
real-time-collaboration-engine
Build real-time collaborative editing with WebSockets, OT/CRDT conflict resolution, and presence awareness. Implements cursor tracking, optimistic updates, and offline sync. Use for collaborative editors, whiteboards, video editing. Activate on "real-time collaboration", "WebSocket sync", "multiplayer editing", "CRDT", "presence awareness". NOT for simple chat, request-response APIs, or single-user apps.
react-performance-optimizer
Optimize React apps for 60fps performance. Implements memoization, virtualization, code splitting, bundle optimization. Use for slow renders, large lists, bundle bloat. Activate on "React performance", "slow render", "useMemo", "bundle size", "virtualization". NOT for backend optimization, non-React frameworks, or premature optimization.
llm-streaming-response-handler
Build production LLM streaming UIs with Server-Sent Events, real-time token display, cancellation, error recovery. Handles OpenAI/Anthropic/Claude streaming APIs. Use for chatbots, AI assistants, real-time text generation. Activate on "LLM streaming", "SSE", "token stream", "chat UI", "real-time AI". NOT for batch processing, non-streaming APIs, or WebSocket bidirectional chat.
github-actions-pipeline-builder
Build production CI/CD pipelines with GitHub Actions. Implements matrix builds, caching, deployments, testing, security scanning. Use for automated testing, deployments, release workflows. Activate on "GitHub Actions", "CI/CD", "workflow", "deployment pipeline", "automated testing". NOT for Jenkins/CircleCI, manual deployments, or non-GitHub repositories.