snp-connection-monitoring/frontend/src/services/apiClient.ts
HYOJIN 97e5a24343 feat: 로그인 프로세스 제거 + 사용자 역할 토글 버튼
- JWT 인증 및 LoginPage 제거, SecurityConfig permitAll 전환
- @PreAuthorize 어노테이션 전체 제거 (@EnableMethodSecurity 비활성화)
- ADMIN/MANAGER/USER 역할 토글 버튼 (헤더) + localStorage 연동
- X-User-Id 헤더 기반 사용자 식별 (ApiKeyController, ApiKeyRequestController)
- RoleGuard 컴포넌트로 관리자 전용 페이지 접근 제어
- WebViewController 루트 리다이렉트 수정 (이중 context-path 방지)

closes #35
2026-04-13 09:27:17 +09:00

48 lines
1.2 KiB
TypeScript

import type { ApiResponse } from '../types/api';
const BASE_URL = '/snp-connection/api';
let currentUserId: number = 1;
export const setApiClientUserId = (userId: number) => {
currentUserId = userId;
};
const request = async <T>(url: string, options: RequestInit = {}): Promise<ApiResponse<T>> => {
const headers: Record<string, string> = {
'Content-Type': 'application/json',
'X-User-Id': String(currentUserId),
...options.headers as Record<string, string>,
};
const response = await fetch(`${BASE_URL}${url}`, {
...options,
headers,
});
const data = await response.json() as ApiResponse<T>;
return data;
};
export const get = <T>(url: string): Promise<ApiResponse<T>> => {
return request<T>(url, { method: 'GET' });
};
export const post = <T>(url: string, body?: unknown): Promise<ApiResponse<T>> => {
return request<T>(url, {
method: 'POST',
body: body ? JSON.stringify(body) : undefined,
});
};
export const put = <T>(url: string, body?: unknown): Promise<ApiResponse<T>> => {
return request<T>(url, {
method: 'PUT',
body: body ? JSON.stringify(body) : undefined,
});
};
export const del = <T>(url: string): Promise<ApiResponse<T>> => {
return request<T>(url, { method: 'DELETE' });
};