首页/ AI 技能 / @skilllib/skill-2117939930272412433
Skill站外收录 @skilllib/skill-2117939930272412433

authentication

通过安全的 HttpOnly Cookies 实现身份验证与令牌管理,确保敏感信息免受 XSS 攻击,同时支持服务端组件的无缝集成,利用中间件对路由进行前置保护,避免因客户端存储导致的性能损耗与渲染阻塞。

0.0 (0) 31 次安装 原作者 编程导航
收录于 2026-01-22
测试与安全 AI 技能

Skills.MD

# 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](references/auth-implementation.md) (See "Setting Tokens"). 2. **Access**: Read tokens in Server Components via `cookies().get()`. - _Reference_: [Auth Implementation](references/auth-implementation.md) (See "Reading Tokens"). 3. **Protection**: Guard routes in `middleware.ts` before rendering. - _Reference_: [Auth Implementation](references/auth-implementation.md) (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.

评论 0

还没有评论,来抢沙发。