以慣用方式在 NestJS 中實作 JWT 驗證
何時使用: 你需要支援 refresh token 的 JWT,但不想從頭手動串接 passport 模組。
前置條件
- NestJS 專案 — nest new my-app
步驟
-
請求實作Use the NestJS skill. Add JWT auth with refresh tokens to this project.✓ 已複製→ Claude 載入 NestJS 參考資料,產出慣用的模組結構(AuthModule、JwtStrategy、guards)
-
新增測試Now add e2e tests for the auth endpoints using the testing skill.✓ 已複製→ 遵循 NestJS 慣例的 Jest + supertest 測試檔案
結果: 符合生產環境模式的 JWT 驗證,並附有測試。
注意事項
- Claude 將 NestJS 裝飾器與 Express 中介軟體模式混用 — 明確要求「僅使用 NestJS 慣用寫法 — 不使用原生 Express」
搭配使用: github