refactor: 안쓰는 코드, 설정 함수 수정

This commit is contained in:
yoosangwook 2024-08-08 13:49:44 +09:00
parent a5f38502a2
commit cc7f71be6a
4 changed files with 21 additions and 11 deletions

View File

@ -2,8 +2,7 @@
import { Button, Table, TableBody, TableCell, TableColumn, TableHeader, TableRow } from '@nextui-org/react'
import { AxiosType } from '@/const/axiosConst'
import { useAxios } from '@/hooks/useAxios'
import { AxiosType, useAxios } from '@/hooks/useAxios'
// import { get } from '@/lib/Axios'
import QSelect from '@/components/ui/QSelect'
@ -21,7 +20,7 @@ export default function changelogPage() {
url: '/api/user/find-all',
}
const users = await get(params)
console.log(users)
console.log('users', users)
}
const data = [

View File

@ -4,8 +4,7 @@ import { useEffect, useMemo, useState } from 'react'
import Link from 'next/link'
import { AxiosType } from '@/const/axiosConst'
import { useAxios } from '@/hooks/useAxios'
import { AxiosType, useAxios } from '@/hooks/useAxios'
import { Button } from '@nextui-org/react'
@ -69,7 +68,6 @@ export default function Intro() {
// const response = await fetch('https://www.ag-grid.com/example-assets/space-mission-data.json')
// const data = await response.json()
const data = await get({ type: AxiosType.EXTERNAL, url: 'https://www.ag-grid.com/example-assets/space-mission-data.json' })
console.log(data)
setGridProps({ ...gridProps, gridData: data })
}
fetchData()

View File

@ -1,4 +0,0 @@
export const AxiosType = {
INTERNAL: 'Internal',
EXTERNAL: 'External',
}

View File

@ -1,6 +1,10 @@
import { AxiosType } from '@/const/axiosConst'
import axios from 'axios'
export const AxiosType = {
INTERNAL: 'Internal',
EXTERNAL: 'External',
}
export function useAxios() {
const getInstances = (type) => {
return axios.create({
@ -11,6 +15,19 @@ export function useAxios() {
})
}
axios.interceptors.request.use((config) => {
// config['Authorization'] = localStorage.getItem('token')
//TODO: 인터셉터에서 추가 로직 구현
return config
})
axios.interceptors.request.use(undefined, (error) => {
//TODO: 인터셉터에서 에러 처리 로직 구현
// if (error.isAxiosError && e.response?.status === 401) {
// localStorage.removeItem('token')
// }
})
const get = async ({ type, url }) => {
return await getInstances(type)
.get(url)