NestJSでイディオマティックなJWT認証を実装する
使うタイミング: リフレッシュトークン付きのJWT認証が必要で、passportモジュールをゼロから組み立てたくない場合。
前提条件
- NestJSプロジェクト — nest new my-app
フロー
-
実装をリクエストするUse the NestJS skill. Add JWT auth with refresh tokens to this project.✓ コピーしました→ ClaudeがNestJSリファレンスを読み込み、イディオマティックなモジュール構成(AuthModule、JwtStrategy、ガード)を生成する
-
テストを追加するNow add e2e tests for the auth endpoints using the testing skill.✓ コピーしました→ NestJSの規約に沿ったJest + supertestのテストファイル
結果: テスト付きの本番レベルJWT認証パターン。
注意点
- ClaudeがNestJSデコレータとExpressミドルウェアパターンを混在させる — 「NestJSのイディオムのみ — 生のExpressは使わないこと」と明示する