22
33import React , { useEffect , useState , useCallback } from 'react' ;
44import { useRouter } from 'next/navigation' ;
5- import axios from 'axios' ;
65import { useSession } from 'next-auth/react' ;
76import { API_URLS } from '@/constants/urls' ;
87import '@/styles/pages/community/community.scss' ;
98import { Params , Post , Comment } from '@/types/post' ;
109import { FaThumbsUp , FaRegThumbsUp } from "react-icons/fa6" ;
1110import Link from 'next/link' ;
1211import { ALERT_MESSAGES } from '@/constants/alert_message' ;
12+ import { axiosInstance } from '@/services/axiosInstance' ;
1313
1414export default function PostDetailPage ( { params } : { params : Params } ) {
1515 const { id } = params ;
@@ -30,7 +30,7 @@ export default function PostDetailPage({ params }: { params: Params }) {
3030 // 게시글 정보 가져오기
3131 const fetchPost = useCallback ( async ( ) => {
3232 try {
33- const response = await axios . get ( `${ API_URLS . POSTS } /${ id } ` ) ;
33+ const response = await axiosInstance . get ( `${ API_URLS . POSTS } /${ id } ` ) ;
3434 setPost ( response . data ) ;
3535 } catch ( error ) {
3636 console . error ( 'Error fetching post:' , error ) ;
@@ -41,7 +41,7 @@ export default function PostDetailPage({ params }: { params: Params }) {
4141 // 댓글 목록 가져오기
4242 const fetchComments = useCallback ( async ( ) => {
4343 try {
44- const response = await axios . get ( `${ API_URLS . POSTS } /${ id } /comments` ) ;
44+ const response = await axiosInstance . get ( `${ API_URLS . POSTS } /${ id } /comments` ) ;
4545 setComments ( response . data ) ;
4646 } catch ( error ) {
4747 console . error ( 'Error fetching comments:' , error ) ;
@@ -53,7 +53,7 @@ export default function PostDetailPage({ params }: { params: Params }) {
5353 const fetchRecommendation = useCallback ( async ( ) => {
5454 try {
5555 // 토큰 포함
56- const response = await axios . get (
56+ const response = await axiosInstance . get (
5757 `${ API_URLS . POSTS } /${ id } /recommend` ,
5858 { headers : { Authorization : `Bearer ${ accessToken } ` } }
5959 ) ;
@@ -75,7 +75,7 @@ export default function PostDetailPage({ params }: { params: Params }) {
7575 try {
7676 if ( ! window . confirm ( ALERT_MESSAGES . CONFIRM . CHECK_DELETE ) ) return ;
7777
78- await axios . delete ( `${ API_URLS . POSTS } /${ id } ` , {
78+ await axiosInstance . delete ( `${ API_URLS . POSTS } /${ id } ` , {
7979 headers : { Authorization : `Bearer ${ accessToken } ` } ,
8080 } ) ;
8181
@@ -95,7 +95,7 @@ export default function PostDetailPage({ params }: { params: Params }) {
9595 return ;
9696 }
9797
98- await axios . post (
98+ await axiosInstance . post (
9999 `${ API_URLS . POSTS } /${ id } /comments` ,
100100 { content : newComment } ,
101101 { headers : { Authorization : `Bearer ${ accessToken } ` } }
@@ -114,7 +114,7 @@ export default function PostDetailPage({ params }: { params: Params }) {
114114 try {
115115 if ( ! window . confirm ( ALERT_MESSAGES . CONFIRM . CHECK_DELETE ) ) return ;
116116
117- await axios . delete ( `${ API_URLS . POSTS } /comments/${ commentId } ` , {
117+ await axiosInstance . delete ( `${ API_URLS . POSTS } /comments/${ commentId } ` , {
118118 headers : { Authorization : `Bearer ${ accessToken } ` } ,
119119 } ) ;
120120
@@ -140,7 +140,7 @@ export default function PostDetailPage({ params }: { params: Params }) {
140140 return ;
141141 }
142142
143- await axios . put (
143+ await axiosInstance . put (
144144 `${ API_URLS . POSTS } /comments/${ commentId } ` ,
145145 { content : editedComment } ,
146146 { headers : { Authorization : `Bearer ${ accessToken } ` } }
@@ -160,7 +160,7 @@ export default function PostDetailPage({ params }: { params: Params }) {
160160 // 추천 토글
161161 const toggleRecommendation = async ( ) => {
162162 try {
163- const response = await axios . post (
163+ const response = await axiosInstance . post (
164164 `${ API_URLS . POSTS } /${ id } /recommend` ,
165165 { } ,
166166 { headers : { Authorization : `Bearer ${ accessToken } ` } }
0 commit comments