Communitygithub.com

ComeOnOliver/skillshub

A conceptual skill for building an API client in Next.js that handles JWT tokens

skillshub とは?

skillshub is a Claude Code agent skill that a conceptual skill for building an API client in Next.js that handles JWT tokens.

対応✓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に質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Frontend API Client with JWT Skill

When to Use This Skill

Use this conceptual skill when you need to implement a robust API client in Next.js that properly handles JWT tokens for authentication. This skill is appropriate for:

  • Creating centralized API communication layer in Next.js applications
  • Managing JWT-based authentication across multiple API endpoints
  • Handling token expiration and refresh scenarios
  • Standardizing error response parsing and handling
  • Implementing secure API communication patterns

This skill should NOT be used for:

  • Applications without JWT-based authentication
  • Static sites without API communication needs
  • Applications using alternative authentication methods (API keys, OAuth 2.0 client credentials, etc.)
  • Simple applications with minimal API interaction

Prerequisites

  • Next.js application (either App Router or Pages Router)
  • Understanding of JWT (JSON Web Token) concepts
  • Knowledge of HTTP headers and authorization mechanisms
  • Basic understanding of asynchronous JavaScript operations
  • Awareness of client-side vs server-side execution contexts

Conceptual Implementation Framework

Authorization Header Attachment Capability

  • Automatically attach JWT tokens to API requests as Authorization headers
  • Determine when to include tokens based on request type and endpoint
  • Handle token attachment for both client-side and server-side requests
  • Manage token inclusion in cross-origin requests appropriately
  • Ensure proper header formatting ("Bearer ")

Token Expiry Handling Capability

  • Detect JWT token expiration before making API requests
  • Implement automatic token refresh mechanisms
  • Handle token refresh failures gracefully
  • Maintain session continuity during token refresh
  • Coordinate token refresh across multiple concurrent requests
  • Store updated tokens securely after refresh

Error Response Parsing Capability

  • Parse structured error responses from API endpoints
  • Identify authentication-related errors (401, 403) for special handling
  • Extract meaningful error messages for user feedback
  • Handle different error response formats consistently
  • Distinguish between client errors, server errors, and network issues
  • Provide appropriate user feedback based on error types

API Call Centralization Capability

  • Create a unified interface for all API communications
  • Standardize request and response handling across the application
  • Implement consistent error handling and logging
  • Manage request/response interceptors for cross-cutting concerns
  • Provide type-safe API call patterns (when using TypeScript)
  • Enable request caching and deduplication where appropriate

Expected Input/Output

Input Requirements:

  1. JWT Token Management:

    • Valid JWT token for authorization
    • Token refresh endpoint configuration
    • Token storage mechanism (localStorage, cookies, etc.)
    • Token expiration time and refresh timing
  2. API Configuration:

    • Base API URL for requests
    • Request timeout settings
    • Custom headers and request options
    • Endpoint-specific configurations
  3. Request Parameters:

    • HTTP method (GET, POST, PUT, DELETE, etc.)
    • Request URL or endpoint identifier
    • Request body for POST/PUT operations
    • Query parameters and path variables

Output Formats:

  1. Successful API Response:

    • HTTP 200-299 status codes
    • Parsed response data matching expected format
    • Updated token information when applicable
    • Consistent response structure across all endpoints
  2. Authentication Error Response:

    • HTTP 401 Unauthorized for expired/invalid tokens
    • Automatic token refresh attempt
    • Redirect to login page after refresh failure
    • Clear error messaging for authentication issues
  3. Authorization Error Response:

    • HTTP 403 Forbidden for insufficient permissions
    • Appropriate error handling based on permission level
    • User feedback for access restriction
  4. General Error Response:

    • Structured error object with message and code
    • Appropriate HTTP status code
    • Detailed error information for debugging
    • User-friendly error messages for UI display

Integration Patterns

Client-Side Integration

  • Handle API calls from client components and client-side rendering
  • Manage token storage and retrieval in browser context
  • Implement request interceptors for header attachment
  • Coordinate with authentication state management

Server-Side Integration (when applicable)

  • Handle API calls from server components
  • Manage token transmission securely between server and client
  • Implement server-side token validation
  • Handle server-side error responses appropriately

React Component Integration

  • Provide hooks for API communication in functional components
  • Enable context-based API client access
  • Support both functional and class component patterns
  • Implement proper cleanup and cancellation mechanisms

Security Considerations

  1. Token Storage: Secure JWT token storage to prevent XSS attacks
  2. Header Transmission: Use HTTPS for all API communications
  3. Token Refresh: Implement secure token refresh mechanisms
  4. Error Information: Avoid exposing sensitive information in error messages
  5. Request Validation: Validate request parameters before sending
  6. Response Validation: Verify response integrity and format
  7. Cross-Site Requests: Implement proper CORS handling

Performance Implications

  • Optimize token retrieval and attachment for minimal overhead
  • Implement efficient token refresh to avoid blocking requests
  • Consider request caching strategies for improved performance
  • Minimize redundant API calls through proper state management
  • Implement request batching where appropriate
  • Monitor and optimize network request timing

Error Handling and Validation

  • Validate JWT token format and expiration before requests
  • Handle network connectivity issues gracefully
  • Implement retry mechanisms for transient failures
  • Provide fallback behaviors for critical API failures
  • Log errors appropriately for debugging without exposing sensitive information
  • Implement circuit breaker patterns for service resilience

Testing Considerations

  • Test token attachment functionality with valid/invalid tokens
  • Verify token refresh mechanisms work correctly
  • Validate error response parsing across different error types
  • Test API client behavior in both client and server contexts
  • Verify proper cleanup and cancellation of requests
  • Test concurrent request handling and token refresh coordination

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

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

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

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

All TypeScript types are defined in `frontend/types/index.ts`. Types match backend API response structure and provide type safety across the frontend application.

ComeOnOliver/skillshub

Use when working with Next.js App Router tasks - creating pages in /app/, setting up dynamic routes ([id]/page.tsx), implementing nested layouts/templates (layout.tsx), optimizing Server/Client components, or building ERP role-based pages (admin/teacher/student dashboards). Auto-use for all /app/ directory operations, dynamic routing, and App Router-specific features.

ComeOnOliver/skillshub

Apple-inspired clean, minimal, premium UI design. Use when building modern interfaces requiring exceptional UX, clean aesthetics, or Apple-like polish. Triggers on: clean UI, modern design, Apple style, minimal, premium, user-friendly, UX.

ComeOnOliver/skillshub

Use when creating UI designs to avoid generic "AI slop" aesthetics. Enforces distinctive typography, cohesive color systems, purposeful motion, and atmospheric backgrounds. Critical for landing pages, dashboards, and branded interfaces.

ComeOnOliver/skillshub

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

関連スキル