Skip to main content

API & Auth Interceptors

MStore Dashboard menggunakan Nuxt’s built-in $fetch dengan custom interceptors untuk menangani JWT authentication, auto token refresh, dan error handling.

Security Architecture

Token Storage Strategy

Auth Plugin Implementation

Using the API Client

In Composables

In Components

Direct $fetch (without auth)

Untuk public endpoints yang tidak memerlukan authentication:

Token Refresh Flow

Error Handling

API Error Types

Handling Errors in Composables

Request Interceptor Options

Adding Custom Headers

With Query Parameters

POST with Body

File Upload

Timeout and Retry

Response Type Hints

Multiple Simultaneous Requests

Saat ada multiple request bersamaan dan token expired:
Ini ditangani oleh refreshPromise deduplication:

Best Practices

Next Steps

API Layer Pattern

Feature API organization

Authentication

Complete auth implementation