Add JSDoc documentation and file headers to all source files
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,17 @@
|
||||
// The Lucia project.
|
||||
// Copyright 2023-2026 DSP, inc. All rights reserved.
|
||||
// Authors:
|
||||
// imacat.yang@dsp.im (imacat), 2023/9/23
|
||||
/**
|
||||
* @module apiClient Centralized axios instance with request/response
|
||||
* interceptors for authentication token management and automatic
|
||||
* 401 token refresh with request queuing.
|
||||
*/
|
||||
|
||||
import axios from 'axios';
|
||||
import { getCookie, deleteCookie } from '@/utils/cookieUtil.js';
|
||||
|
||||
/** Axios instance configured with auth interceptors. */
|
||||
const apiClient = axios.create();
|
||||
|
||||
// Request interceptor: automatically attach Authorization header
|
||||
@@ -16,11 +27,19 @@ apiClient.interceptors.request.use((config) => {
|
||||
let isRefreshing = false;
|
||||
let pendingRequests = [];
|
||||
|
||||
/**
|
||||
* Resolves all pending requests with the new access token.
|
||||
* @param {string} newToken - The refreshed access token.
|
||||
*/
|
||||
function onRefreshSuccess(newToken) {
|
||||
pendingRequests.forEach((cb) => cb(newToken));
|
||||
pendingRequests = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Rejects all pending requests with the refresh error.
|
||||
* @param {Error} error - The token refresh error.
|
||||
*/
|
||||
function onRefreshFailure(error) {
|
||||
pendingRequests.forEach((cb) => cb(null, error));
|
||||
pendingRequests = [];
|
||||
|
||||
Reference in New Issue
Block a user