diff --git a/composables/useApi.ts b/composables/useApi.ts index ebf4f30..e0767d5 100644 --- a/composables/useApi.ts +++ b/composables/useApi.ts @@ -15,7 +15,7 @@ export const useApi = ( const method = options.method ? options.method.toUpperCase() : 'GET' - return useFetch(() => `${config.public.apiBase}${path}`, { + return useFetch(() => `${config.public.apiBase}${config.public.contextPath}${path}`, { method: method as any, // 타입 강제 우회 body: options.body, query: options.query, diff --git a/nuxt.config.ts b/nuxt.config.ts index 456d0aa..ea1d861 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -37,7 +37,8 @@ export default defineNuxtConfig({ }, runtimeConfig: { public: { - apiBase: 'http://localhost' + apiBase: process.env.API_BASE || 'http://localhost', + contextPath: process.env.CONTEXT_PATH || '/service', } }, typescript: { diff --git a/stores/user.ts b/stores/user.ts index 74e9877..d80c44e 100644 --- a/stores/user.ts +++ b/stores/user.ts @@ -16,13 +16,6 @@ export const useUserStore = defineStore("user", () => { role: string lastLoginAt: string } - - interface LoginResponse { - code: number - message: string - description: string - data: LoginData - } // 게터 const isAdmin = computed(() => user.value?.role === "admin"); @@ -32,14 +25,14 @@ export const useUserStore = defineStore("user", () => { try { // 실제 API 호출로 대체할 수 있습니다 - const {data, error: _error } = await useApi('/service/login', { + const {data, error: _error } = await useApi>('/login', { method: 'post', body: { userId, password } }) let mockUser; - if(data && data.value && data.value.code === 200){ + if(data && data.value && data.value.success){ mockUser = data.value.data; }else{ throw new Error("아이디 또는 비밀번호가 올바르지 않습니다."); diff --git a/types/common.ts b/types/common.ts new file mode 100644 index 0000000..ebea1f2 --- /dev/null +++ b/types/common.ts @@ -0,0 +1,13 @@ +// types/common.ts +declare global { + interface ApiResponse { + success: boolean + code: number + message: string + description: string + data: T + } +} + +export {} + \ No newline at end of file diff --git a/types/vue3-tui-grid.d.ts b/types/vue3-tui-grid.d.ts index 9a868bd..286360f 100644 --- a/types/vue3-tui-grid.d.ts +++ b/types/vue3-tui-grid.d.ts @@ -5,5 +5,5 @@ declare module 'vue3-tui-grid' { export default TuiGrid; export type TuiGridElement = any; export type GridEvent = any; - } +} \ No newline at end of file