MCPcopy
hub / github.com/ModelEngine-Group/nexent / fetchWithAuth

Function fetchWithAuth

frontend/lib/auth.ts:50–76  ·  view source on GitHub ↗
(url: string, options: RequestInit = {})

Source from the content-addressed store, hash-verified

48 * Authorization is handled automatically via HttpOnly cookies + server.js proxy.
49 */
50export const fetchWithAuth = async (url: string, options: RequestInit = {}) => {
51 // Frontend pre-check: detect session expiry without hitting backend
52 if (typeof window !== "undefined") {
53 if (
54 !authFlowState.isExplicitLogoutInProgress() &&
55 hasAuthCookies() &&
56 !checkSessionValid()
57 ) {
58 handleSessionExpired();
59 throw new ApiError(
60 STATUS_CODES.TOKEN_EXPIRED,
61 "Login expired, please login again"
62 );
63 }
64 }
65
66 const isFormData = options.body instanceof FormData;
67 const headers = {
68 ...(isFormData ? {} : { "Content-Type": "application/json" }),
69 ...options.headers,
70 };
71
72 return fetchWithErrorHandling(url, {
73 ...options,
74 headers,
75 });
76};
77
78/**
79 * Get common headers for API requests.

Callers 15

listUsersFunction · 0.90
getUserFunction · 0.90
updateUserFunction · 0.90
deleteUserFunction · 0.90
listTenantsFunction · 0.90
getTenantFunction · 0.90
createTenantFunction · 0.90
updateTenantFunction · 0.90
deleteTenantFunction · 0.90
getTenantUsersFunction · 0.90
listGroupsFunction · 0.90
getGroupFunction · 0.90

Calls 4

hasAuthCookiesFunction · 0.90
checkSessionValidFunction · 0.90
handleSessionExpiredFunction · 0.90
fetchWithErrorHandlingFunction · 0.90

Tested by

no test coverage detected