技能 frontend-api-client-with-jwt
📦

frontend-api-client-with-jwt

v1.0.0 中風險

在 Next.js 中建置具 JWT 處理的 API 用戶端

在 API 用戶端中管理 JWT 驗證相當複雜且容易出錯。此技能提供一套框架,用於在 Next.js 應用程式中實作安全、集中式的 API 通訊,並具備自動權杖更新、錯誤處理與一致的回應解析。

支援: Claude Codex Code(CC)
📊 72 尚可
1

下載技能 ZIP

2

在 Claude 中上傳

前往 設定 → 功能 → 技能 → 上傳技能

3

開啟並開始使用

測試它

正在使用「frontend-api-client-with-jwt」。 Create an API client that handles JWT authentication

預期結果:

  • 以 base URL 與 timeout 設定集中式 API 用戶端
  • 以 Bearer 權杖格式附加 Authorization header
  • 在 401 回應時觸發權杖更新機制
  • 針對驗證失敗的錯誤處理並提供使用者回饋
  • 用於記錄與 header 注入的請求攔截器

正在使用「frontend-api-client-with-jwt」。 How do I handle token expiration in my Next.js app

預期結果:

  • 在發出請求前驗證權杖是否到期
  • 在到期前主動更新權杖
  • 在更新失敗時導向登入
  • 更新後安全地儲存權杖
  • 在多個並行請求間協調更新流程

正在使用「frontend-api-client-with-jwt」。 What security considerations exist for JWT in frontend

預期結果:

  • 所有 API 通訊都使用 HTTPS
  • 安全地儲存權杖以防止 XSS 攻擊
  • 實作正確的 CORS 處理
  • 避免在錯誤訊息中暴露敏感資料
  • 處理前先驗證回應

安全審計

中風險
v6 • 6/28/2026

The static findings are documentation terms in SKILL.md, not executable code, command execution, scanning, or exfiltration behavior. One semantic concern remains: the skill lists localStorage as a JWT storage option without enough warning about XSS exposure, so publication should include a security warning.

1
已掃描檔案
171
分析行數
3
Review items
0
False positives ignored

Confirmed security concerns (3)

Security-Sensitive Token Storage Guidance
Static verdict: TRUE POSITIVE as a guidance risk, not as executable malware. The skill lists browser storage options for JWT tokens, including localStorage, which can expose bearer tokens to XSS if used without strong safeguards.
The line explicitly names token storage mechanisms in JWT guidance. The file is prose rather than code, so the risk is insecure implementation advice rather than direct credential access.
False Positive: JWT and HTTP Status Terminology
Static verdict: FALSE POSITIVE. The weak cryptographic algorithm detections point to a JWT description and an HTTP 200-299 status range, with no cryptographic API, algorithm selection, or hashing implementation present.
Both locations are plain documentation text. I found no code path, crypto function, or recommendation to use a weak algorithm.
False Positive: Reconnaissance Terms in API Guidance
Static verdict: FALSE POSITIVE. The system and network reconnaissance detections are ordinary API-client documentation about valid tokens, HTTP 401 handling, context access, error messages, refresh performance, and token tests.
The referenced lines contain no shell commands, port scanning, host discovery, probing loops, or data collection behavior. They are conceptual guidance for API request handling and tests.
審計單位: codex 檢視審計紀錄 →

品質評分

55
架構
100
可維護性
87
內容
70
社群
56
安全
83
規範符合度

你可以打造什麼

Next.js API 用戶端架構

為 Next.js 應用程式設計集中式 API 用戶端,具備安全的 JWT 權杖處理與自動更新。

驗證流程整合

在用戶端與伺服器端元件中實作具權杖更新的無縫驗證流程。

React Hook API 模式

建置用於 API 通訊的自訂 hooks,能一致地處理 JWT 權杖與錯誤。

試試這些提示

基本 API 用戶端設定
在 Next.js 中建立一個 API 用戶端,能自動在請求中附加 JWT 權杖,並在 401 錯誤時處理權杖更新。
權杖更新實作
在 Next.js 應用程式中於 JWT 到期前實作自動權杖更新,以避免請求失敗。
錯誤回應處理
為 API 用戶端建置錯誤回應解析,能識別 401 與 403 錯誤並適當地重新導向使用者。
請求攔截器
為 Next.js API 用戶端建立請求攔截器,加入 authorization headers 並記錄送出的請求。

最佳實務

  • 安全地儲存 JWT 權杖,並在發出 API 請求前驗證,以避免不必要的呼叫
  • 在到期前主動更新權杖,而不是在 401 錯誤後被動處理
  • 所有 API 通訊都使用 HTTPS 以保護傳輸中的權杖

避免

  • 在沒有 XSS 防護的情況下將 JWT 權杖存放在 localStorage,會使權杖暴露於腳本注入攻擊
  • 在沒有錯誤處理的情況下發出 API 呼叫會導致靜默失敗與不佳的使用者體驗
  • 在缺乏協調的情況下實作權杖更新,可能導致並行請求的競態條件

常見問題

此技能與 Next.js App Router 和 Pages Router 相容嗎?
是,這些概念適用於 Next.js App Router 與 Pages Router,但需依情境進行實作。
可支援的並行 API 請求最大數量是多少?
沒有固定上限。此框架會在不阻塞的情況下協調跨請求的權杖更新。
這如何與現有的驗證提供者整合?
此技能提供適用於任何 JWT 驗證的模式。請整合你現有的權杖儲存與更新端點。
在此實作中權杖是否安全地儲存?
此技能描述安全模式。實際實作取決於儲存方式,例如 cookies 或安全儲存。
若權杖更新反覆失敗,應該怎麼做?
在更新失敗後將使用者導向登入。清除已儲存的權杖並提供清楚的錯誤訊息。
這與使用 Axios 攔截器相比如何?
此技能提供類似的攔截器模式。實作可使用 fetch、Axios 或任何 HTTP 用戶端程式庫。

開發者詳細資訊

檔案結構

📄 SKILL.md