11import { FC , useState , useEffect } from 'react' ;
22import axios from 'axios' ;
3+ import { useCookies } from 'react-cookie' ;
34import { fetchDonations , fetchDonationAmount } from '@/util/charity' ;
45
56interface DonationData {
@@ -17,6 +18,7 @@ interface CharityData {
1718const DonatePage : FC = ( ) => {
1819 const [ loading , setLoading ] = useState ( false ) ;
1920 const [ donationData , setDonationData ] = useState < DonationData | null > ( null ) ;
21+ const [ cookies ] = useCookies ( [ 'token' ] ) ;
2022 const [ charities , setCharities ] = useState < CharityData [ ] > ( [ ] ) ;
2123
2224 useEffect ( ( ) => {
@@ -34,15 +36,17 @@ const DonatePage: FC = () => {
3436 const handleDonate = async ( fixed : string , amount : string ) => {
3537 setLoading ( true ) ;
3638 try {
37- const response = await axios . post (
38- 'http://localhost:8000/api/donation' ,
39- { fixed, amount } ,
40- {
41- headers : { 'Content-Type' : 'application/json' } ,
42- responseType : 'text' ,
43- validateStatus : ( ) => true ,
44- }
45- ) ;
39+ const response = await axios . post ( 'http://localhost:8000/api/donation' , {
40+ fixed,
41+ amount
42+ } , {
43+ headers : {
44+ 'Content-Type' : 'application/json' ,
45+ 'Authorization' : `Bearer ${ cookies . token } `
46+ } ,
47+ responseType : 'text' ,
48+ validateStatus : ( ) => true
49+ } ) ;
4650
4751 const data = JSON . parse ( response . data ) ;
4852 if ( data . url ) {
0 commit comments