Communitygithub.com

ComeOnOliver/skillshub

一個概念性技能,用於在 Next.js 中建置能處理 JWT 令牌的 API 客戶端。

skillshub 是什麼?

此技能提供一個概念性框架,用於在 Next.js 應用程式中實作一個強大的 API 客戶端,特別專注於 JWT(JSON Web Token)令牌的管理。它指導開發者建立一個集中化的 API 通訊層,能夠自動附加授權標頭、優雅地處理令牌過期與重新整理,並標準化錯誤回應的解析。此技能涵蓋客戶端與伺服器端整合模式,包括 React 元件的整合,並考量安全性(如安全的令牌儲存與 HTTPS 傳輸)與效能最佳化(如請求快取與批次處理)。它支援 Next.js 的 App Router 與 Pages Router,適用於需要 JWT 驗證的中大型應用程式,但不建議用於靜態網站或使用其他驗證方法的應用程式。

相容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ComeOnOliver/skillshub/tree/HEAD/skills/aiskillstore/marketplace/abdul-haseeb360/frontend-api-client-with-jwt

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

前端 API 客戶端(含 JWT)技能

使用時機

當您需要在 Next.js 中實作一個能妥善處理 JWT 令牌進行驗證的強大 API 客戶端時,請使用此概念性技能。此技能適用於:

  • 在 Next.js 應用程式中建立集中化的 API 通訊層
  • 跨多個 API 端點管理基於 JWT 的驗證
  • 處理令牌過期與重新整理情境
  • 標準化錯誤回應的解析與處理
  • 實作安全的 API 通訊模式

不應使用此技能的情況:

  • 不使用 JWT 驗證的應用程式
  • 無 API 通訊需求的靜態網站
  • 使用其他驗證方法(API 金鑰、OAuth 2.0 用戶端憑證等)的應用程式
  • API 互動極少的簡單應用程式

先決條件

  • Next.js 應用程式(App Router 或 Pages Router)
  • 了解 JWT (JSON Web Token) 概念
  • 具備 HTTP 標頭與授權機制的知識
  • 基本了解非同步 JavaScript 運作
  • 認識客戶端與伺服器端執行的差異

概念性實作架構

授權標頭附加能力

  • 自動將 JWT 令牌以 Authorization 標頭附加至 API 請求
  • 根據請求類型與端點決定是否包含令牌
  • 處理客戶端與伺服器端請求的令牌附加
  • 管理跨來源請求中的令牌包含
  • 確保標頭格式正確("Bearer ")

令牌過期處理能力

  • 在發送 API 請求前偵測 JWT 令牌是否過期
  • 實作自動令牌重新整理機制
  • 優雅處理令牌重新整理失敗
  • 在令牌重新整理期間維持階段連線
  • 協調多個並行請求的令牌重新整理
  • 重新整理後安全儲存更新後的令牌

錯誤回應解析能力

  • 解析來自 API 端點的結構化錯誤回應
  • 識別驗證相關錯誤(401, 403)以進行特殊處理
  • 提取有意義的錯誤訊息供使用者回饋
  • 一致地處理不同的錯誤回應格式
  • 區分用戶端錯誤、伺服器錯誤與網路問題
  • 根據錯誤類型提供適當的使用者回饋

API 呼叫集中化能力

  • 為所有 API 通訊建立統一介面
  • 標準化應用程式的請求與回應處理
  • 實作一致的錯誤處理與記錄
  • 管理請求/回應攔截器以處理跨領域關注點
  • 提供型別安全的 API 呼叫模式(使用 TypeScript 時)
  • 在適當時機啟用請求快取與重複請求去重

預期輸入/輸出

輸入需求:

  1. JWT 令牌管理:

    • 有效的授權 JWT 令牌
    • 令牌重新整理端點設定
    • 令牌儲存機制(localStorage、cookies 等)
    • 令牌過期時間與重新整理時機
  2. API 設定:

    • 請求的基礎 API URL
    • 請求超時設定
    • 自訂標頭與請求選項
    • 端點特定設定
  3. 請求參數:

    • HTTP 方法(GET、POST、PUT、DELETE 等)
    • 請求 URL 或端點識別碼
    • POST/PUT 操作的請求主體
    • 查詢參數與路徑變數

輸出格式:

  1. 成功的 API 回應:

    • HTTP 200-299 狀態碼
    • 符合預期格式的已解析回應資料
    • 適當時更新令牌資訊
    • 跨所有端點的一致回應結構
  2. 驗證錯誤回應:

    • HTTP 401 Unauthorized(憑證過期/無效)
    • 自動嘗試重新整理令牌
    • 重新整理失敗後重新導向至登入頁面
    • 針對驗證問題的清晰錯誤訊息
  3. 授權錯誤回應:

    • HTTP 403 Forbidden(權限不足)
    • 基於權限等級的適當錯誤處理
    • 針對存取限制的使用者回饋
  4. 一般錯誤回應:

    • 包含訊息與代碼的結構化錯誤物件
    • 適當的 HTTP 狀態碼
    • 供除錯用的詳細錯誤資訊
    • 供 UI 顯示的使用者友善錯誤訊息

整合模式

用戶端整合

  • 從用戶端元件與用戶端渲染處理 API 呼叫
  • 在瀏覽器環境中管理令牌儲存與擷取
  • 實作請求攔截器以附加標頭
  • 與驗證狀態管理協調

伺服器端整合(適用時)

  • 從伺服器元件處理 API 呼叫
  • 安全地在伺服器與客戶端之間傳輸令牌
  • 實作伺服器端令牌驗證
  • 適當處理伺服器端錯誤回應

React 元件整合

  • 提供在函式元件中用於 API 通訊的 hooks
  • 啟用基於 context 的 API 客戶端存取
  • 支援函式元件與類別元件模式
  • 實作適當的清理與取消機制

安全性考量

  1. 令牌儲存:安全儲存 JWT 令牌以防止 XSS 攻擊
  2. 標頭傳輸:所有 API 通訊使用 HTTPS
  3. 令牌重新整理:實作安全的令牌重新整理機制
  4. 錯誤資訊:避免在錯誤訊息中揭露敏感資訊
  5. 請求驗證:發送前驗證請求參數
  6. 回應驗證:驗證回應完整性與格式
  7. 跨站請求:實作適當的 CORS 處理

效能影響

  • 最佳化令牌擷取與附加以減少開銷
  • 實作有效率的令牌重新整理以避免阻塞請求
  • 考量請求快取策略以提升效能
  • 透過適當的狀態管理將重複的 API 呼叫降至最低
  • 在適當時機實作請求批次處理
  • 監控並最佳化網路請求時機

錯誤處理與驗證

  • 在請求前驗證 JWT 令牌格式與過期時間
  • 優雅處理網路連線問題
  • 針對暫時性失敗實作重試機制
  • 針對關鍵 API 失敗提供備用行為
  • 適當記錄錯誤以便除錯,同時避免揭露敏感資訊
  • 實作斷路器模式以確保服務復原力

測試考量

  • 使用有效/無效令牌測試令牌附加功能
  • 驗證令牌重新整理機制是否正常運作
  • 驗證不同錯誤類型的錯誤回應解析
  • 在用戶端與伺服器兩種情境下測試 API 客戶端行為
  • 驗證請求的清理與取消機制是否正確
  • 測試並行請求處理與令牌重新整理協調

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

ComeOnOliver/skillshub

Create stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to build a presentation, convert a PPT/PPTX to web, or create slides for a talk/pitch. Helps non-designers discover their aesthetic through visual exploration rather than abstract choices.

ComeOnOliver/skillshub

Next.js 16+ 和 Turbopack — 增量打包、文件系统缓存、开发速度,以及何时使用 Turbopack 与 webpack。

ComeOnOliver/skillshub

SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS/macOS UI best practices.

ComeOnOliver/skillshub

See, Understand, Act on video and audio. See- ingest from local files, URLs, RTSP/live feeds, or live record desktop; return realtime context and playable stream links. Understand- extract frames, build visual/semantic/temporal indexes, and search moments with timestamps and auto-clips. Act- transcode and normalize (codec, fps, resolution, aspect ratio), perform timeline edits (subtitles, text/image overlays, branding, audio overlays, dubbing, translation), generate media assets (image, audio, video), and create real time alerts for events from live streams or desktop capture.

ComeOnOliver/skillshub

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

ComeOnOliver/skillshub

Next.js 15 애플리케이션을 위한 프론트엔드 개발 가이드라인. React 19, TypeScript, Shadcn/ui, Tailwind CSS를 사용한 모던 패턴. Server Components, Client Components, App Router, 파일 구조, Shadcn/ui 컴포넌트, 성능 최적화, TypeScript 모범 사례 포함. 컴포넌트, 페이지, 기능 생성, 데이터 페칭, 스타일링, 라우팅, 프론트엔드 코드 작업 시 사용.

ComeOnOliver/skillshub

Provides Tamagui patterns for config v4, compiler optimization, styled context, and cross-platform styling. Must use when working with Tamagui projects (tamagui.config.ts, @tamagui imports).

ComeOnOliver/skillshub

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.

ComeOnOliver/skillshub

Create high-converting, visually distinctive landing pages. Use when building marketing pages, product launches, SaaS homepages, or any single-page conversion-focused website. Guides section-by-section composition with anti-AI-slop principles.

ComeOnOliver/skillshub

Auto-loaded context for Portfolio Buddy 2 development. Use for ANY task involving: React 19 development, TypeScript, portfolio analysis features, metrics calculations, trading strategy comparison, or working with the Portfolio Buddy 2 codebase. Contains tech stack, known issues, and architectural constraints.

ComeOnOliver/skillshub

Next.js development tooling via MCP. Inspect routes, components, build info, and debug Next.js apps. Use when working on Next.js applications, debugging routing, or inspecting app structure. NOT for general React or non-Next.js projects.

ComeOnOliver/skillshub

Implement UI using Shadcn MCP (atoms/theme) and 21st.dev MCP (complex sections). Use when adding buttons, layouts, or generating landing pages.

ComeOnOliver/skillshub

Best practices and patterns for Next.js App Router, Server Actions, and Routing in this project.

ComeOnOliver/skillshub

The Design System, Theme, and UX rules for the Physical AI Hub.

ComeOnOliver/skillshub

Comprehensive frontend development skill for building modern, performant web applications using ReactJS, NextJS, TypeScript, Tailwind CSS. Includes component scaffolding, performance optimization, bundle analysis, and UI best practices. Use when developing frontend features, optimizing performance, implementing UI/UX designs, managing state, or reviewing frontend code.

ComeOnOliver/skillshub

This document captures learnings from fixing keyboard navigation issues when floating components (Select, DropdownMenu, Popover) have CSS open/close animations.

ComeOnOliver/skillshub

Build Next.js 16 applications with correct patterns and distinctive design. Use when creating pages, layouts, dynamic routes, upgrading from Next.js 15, or implementing proxy.ts. Covers breaking changes (async params/searchParams, Turbopack, cacheComponents) and frontend aesthetics. NOT when building non-React or backend-only applications.

ComeOnOliver/skillshub

Comprehensive Framer Motion animation library for React. Covers motion components, variants, gestures, page transitions, and scroll animations. Use when adding animations to React/Next.js applications.

ComeOnOliver/skillshub

Next.js 16+ uses App Router with Server Components by default. Client Components are only used when interactivity is needed (hooks, event handlers, browser APIs).

ComeOnOliver/skillshub

Build interfaces that resonate, not just render. This skill enforces bold, intentional

相關技能