@@ -86,13 +86,22 @@ export const createQuestion = async (
86
86
question : Omit < QuestionDetail , "id" > ,
87
87
dispatch : Dispatch < QuestionActions >
88
88
) : Promise < boolean > => {
89
+ const accessToken = localStorage . getItem ( "token" ) ;
89
90
return questionClient
90
- . post ( "/" , {
91
- title : question . title ,
92
- description : question . description ,
93
- complexity : question . complexity ,
94
- category : question . categories ,
95
- } )
91
+ . post (
92
+ "/" ,
93
+ {
94
+ title : question . title ,
95
+ description : question . description ,
96
+ complexity : question . complexity ,
97
+ category : question . categories ,
98
+ } ,
99
+ {
100
+ headers : {
101
+ Authorization : `Bearer ${ accessToken } ` ,
102
+ } ,
103
+ }
104
+ )
96
105
. then ( ( res ) => {
97
106
dispatch ( {
98
107
type : QuestionActionTypes . CREATE_QUESTION ,
@@ -183,13 +192,22 @@ export const updateQuestionById = async (
183
192
question : Omit < QuestionDetail , "id" > ,
184
193
dispatch : Dispatch < QuestionActions >
185
194
) : Promise < boolean > => {
195
+ const accessToken = localStorage . getItem ( "token" ) ;
186
196
return questionClient
187
- . put ( `/${ questionId } ` , {
188
- title : question . title ,
189
- description : question . description ,
190
- complexity : question . complexity ,
191
- category : question . categories ,
192
- } )
197
+ . put (
198
+ `/${ questionId } ` ,
199
+ {
200
+ title : question . title ,
201
+ description : question . description ,
202
+ complexity : question . complexity ,
203
+ category : question . categories ,
204
+ } ,
205
+ {
206
+ headers : {
207
+ Authorization : `Bearer ${ accessToken } ` ,
208
+ } ,
209
+ }
210
+ )
193
211
. then ( ( res ) => {
194
212
dispatch ( {
195
213
type : QuestionActionTypes . UPDATE_QUESTION ,
@@ -208,7 +226,12 @@ export const updateQuestionById = async (
208
226
209
227
export const deleteQuestionById = async ( questionId : string ) => {
210
228
try {
211
- await questionClient . delete ( `/${ questionId } ` ) ;
229
+ const accessToken = localStorage . getItem ( "token" ) ;
230
+ await questionClient . delete ( `/${ questionId } ` , {
231
+ headers : {
232
+ Authorization : `Bearer ${ accessToken } ` ,
233
+ } ,
234
+ } ) ;
212
235
return true ;
213
236
} catch {
214
237
return false ;
@@ -229,9 +252,11 @@ export const createImageUrls = async (
229
252
formData : FormData
230
253
) : Promise < { imageUrls : string [ ] ; message : string } | null > => {
231
254
try {
255
+ const accessToken = localStorage . getItem ( "token" ) ;
232
256
const response = await questionClient . post ( "/images" , formData , {
233
257
headers : {
234
258
"Content-Type" : "multipart/form-data" ,
259
+ Authorization : `Bearer ${ accessToken } ` ,
235
260
} ,
236
261
} ) ;
237
262
return response . data ;
0 commit comments