金色时刻 · 15:48
让好资源,触手可及
AGENT SKILL

authentication

authentication 是面向测试与安全的 Agent Skill,来自 HoangNguyen0403/agent-skills-standard。查看技能说明、操作步骤与使用约定,并通过原项目了解详细用法。

Secure token storage (HttpOnly Cookies) and Middleware patterns.

SKILL.md

下载 MD ↓
nameNext.js Authentication
descriptionSecure token storage (HttpOnly Cookies) and Middleware patterns.
metadata{"labels": ["nextjs", "auth", "security", "cookies"], "triggers": {"files": ["middleware.ts", "**/auth.ts", "**/login/page.tsx"], "keywords": ["cookie", "jwt", "session", "localstorage", "auth"]}}

Authentication & Token Management

Priority: P0 (CRITICAL)

Use HttpOnly Cookies for token storage. Never use LocalStorage.

Key Rules

  1. Storage: Use cookies().set() with httpOnly: true, secure: true, sameSite: 'lax'. - Reference: Auth Implementation (See "Setting Tokens").
  2. Access: Read tokens in Server Components via cookies().get(). - Reference: Auth Implementation (See "Reading Tokens").
  3. Protection: Guard routes in middleware.ts before rendering. - Reference: Auth Implementation (See "Middleware Protection").

Anti-Pattern: LocalStorage

  • Security Risk: Vulnerable to XSS.
  • Performance Hit: Incompatible with Server Components (RSC). Forces client hydration and causes layout shift.

来源:HoangNguyen0403/agent-skills-standard · MIT 许可 · 许可原文 · MD 为来源页保存的历史版本