11import { Dispatch } from "react" ;
22import { questionClient } from "../utils/api" ;
33import { isString , isStringArray } from "../utils/typeChecker" ;
4+ import { getToken } from "../utils/token" ;
45
56type TestcaseFiles = {
67 testcaseInputFile : File | null ;
@@ -126,11 +127,11 @@ export const uploadTestcaseFiles = async (
126127 formData . append ( "requestType" , requestType ) ;
127128
128129 try {
129- const accessToken = localStorage . getItem ( "token" ) ;
130+ const accessToken = getToken ( ) ;
130131 const res = await questionClient . post ( "/tcfiles" , formData , {
131132 headers : {
132133 "Content-Type" : "multipart/form-data" ,
133- Authorization : `Bearer ${ accessToken } ` ,
134+ Authorization : accessToken ,
134135 } ,
135136 } ) ;
136137 return res . data ;
@@ -159,7 +160,7 @@ export const createQuestion = async (
159160
160161 const { testcaseInputFileUrl, testcaseOutputFileUrl } = uploadResult . urls ;
161162
162- const accessToken = localStorage . getItem ( "token" ) ;
163+ const accessToken = getToken ( ) ;
163164 return questionClient
164165 . post (
165166 "/" ,
@@ -176,7 +177,7 @@ export const createQuestion = async (
176177 } ,
177178 {
178179 headers : {
179- Authorization : `Bearer ${ accessToken } ` ,
180+ Authorization : accessToken ,
180181 } ,
181182 }
182183 )
@@ -297,7 +298,7 @@ export const updateQuestionById = async (
297298 } ;
298299 }
299300
300- const accessToken = localStorage . getItem ( "token" ) ;
301+ const accessToken = getToken ( ) ;
301302 return questionClient
302303 . put (
303304 `/${ questionId } ` ,
@@ -315,7 +316,7 @@ export const updateQuestionById = async (
315316 } ,
316317 {
317318 headers : {
318- Authorization : `Bearer ${ accessToken } ` ,
319+ Authorization : accessToken ,
319320 } ,
320321 }
321322 )
@@ -337,10 +338,10 @@ export const updateQuestionById = async (
337338
338339export const deleteQuestionById = async ( questionId : string ) => {
339340 try {
340- const accessToken = localStorage . getItem ( "token" ) ;
341+ const accessToken = getToken ( ) ;
341342 await questionClient . delete ( `/${ questionId } ` , {
342343 headers : {
343- Authorization : `Bearer ${ accessToken } ` ,
344+ Authorization : accessToken ,
344345 } ,
345346 } ) ;
346347 return true ;
@@ -363,11 +364,11 @@ export const createImageUrls = async (
363364 formData : FormData
364365) : Promise < { imageUrls : string [ ] ; message : string } | null > => {
365366 try {
366- const accessToken = localStorage . getItem ( "token" ) ;
367+ const accessToken = getToken ( ) ;
367368 const response = await questionClient . post ( "/images" , formData , {
368369 headers : {
369370 "Content-Type" : "multipart/form-data" ,
370- Authorization : `Bearer ${ accessToken } ` ,
371+ Authorization : accessToken ,
371372 } ,
372373 } ) ;
373374 return response . data ;
0 commit comments