1
1
import { Dispatch } from "react" ;
2
2
import { questionClient } from "../utils/api" ;
3
3
import { isString , isStringArray } from "../utils/typeChecker" ;
4
+ import { getToken } from "../utils/token" ;
4
5
5
6
type TestcaseFiles = {
6
7
testcaseInputFile : File | null ;
@@ -126,11 +127,11 @@ export const uploadTestcaseFiles = async (
126
127
formData . append ( "requestType" , requestType ) ;
127
128
128
129
try {
129
- const accessToken = localStorage . getItem ( "token" ) ;
130
+ const accessToken = getToken ( ) ;
130
131
const res = await questionClient . post ( "/tcfiles" , formData , {
131
132
headers : {
132
133
"Content-Type" : "multipart/form-data" ,
133
- Authorization : `Bearer ${ accessToken } ` ,
134
+ Authorization : accessToken ,
134
135
} ,
135
136
} ) ;
136
137
return res . data ;
@@ -159,7 +160,7 @@ export const createQuestion = async (
159
160
160
161
const { testcaseInputFileUrl, testcaseOutputFileUrl } = uploadResult . urls ;
161
162
162
- const accessToken = localStorage . getItem ( "token" ) ;
163
+ const accessToken = getToken ( ) ;
163
164
return questionClient
164
165
. post (
165
166
"/" ,
@@ -176,7 +177,7 @@ export const createQuestion = async (
176
177
} ,
177
178
{
178
179
headers : {
179
- Authorization : `Bearer ${ accessToken } ` ,
180
+ Authorization : accessToken ,
180
181
} ,
181
182
}
182
183
)
@@ -297,7 +298,7 @@ export const updateQuestionById = async (
297
298
} ;
298
299
}
299
300
300
- const accessToken = localStorage . getItem ( "token" ) ;
301
+ const accessToken = getToken ( ) ;
301
302
return questionClient
302
303
. put (
303
304
`/${ questionId } ` ,
@@ -315,7 +316,7 @@ export const updateQuestionById = async (
315
316
} ,
316
317
{
317
318
headers : {
318
- Authorization : `Bearer ${ accessToken } ` ,
319
+ Authorization : accessToken ,
319
320
} ,
320
321
}
321
322
)
@@ -337,10 +338,10 @@ export const updateQuestionById = async (
337
338
338
339
export const deleteQuestionById = async ( questionId : string ) => {
339
340
try {
340
- const accessToken = localStorage . getItem ( "token" ) ;
341
+ const accessToken = getToken ( ) ;
341
342
await questionClient . delete ( `/${ questionId } ` , {
342
343
headers : {
343
- Authorization : `Bearer ${ accessToken } ` ,
344
+ Authorization : accessToken ,
344
345
} ,
345
346
} ) ;
346
347
return true ;
@@ -363,11 +364,11 @@ export const createImageUrls = async (
363
364
formData : FormData
364
365
) : Promise < { imageUrls : string [ ] ; message : string } | null > => {
365
366
try {
366
- const accessToken = localStorage . getItem ( "token" ) ;
367
+ const accessToken = getToken ( ) ;
367
368
const response = await questionClient . post ( "/images" , formData , {
368
369
headers : {
369
370
"Content-Type" : "multipart/form-data" ,
370
- Authorization : `Bearer ${ accessToken } ` ,
371
+ Authorization : accessToken ,
371
372
} ,
372
373
} ) ;
373
374
return response . data ;
0 commit comments