File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { useEffect , useState } from "react" ;
2+ import useLocalStorage from "./useLocalStorage" ;
23
34const useGetRequest = ( ) => {
45 const [ data , setData ] = useState ( null ) ;
56 const [ isLoading , setIsLoading ] = useState ( true ) ;
67 const [ error , setError ] = useState ( "" ) ;
8+ const { userToken } = useLocalStorage ( ) ;
79
810 useEffect ( ( ) => {
9- fetch ( '/api/products' )
11+ fetch ( '/api/products' , { headers : new Headers ( {
12+ 'Backend' : 'earthsearch' ,
13+ 'Authorization' : `Bearer ${ userToken } `
14+ } ) } )
1015 . then ( ( res ) => res . json ( ) )
1116 . then ( ( data ) => {
1217 setData ( data [ 'products' ] )
Original file line number Diff line number Diff line change 11import { useEffect , useState } from "react" ;
2+ import useLocalStorage from "./useLocalStorage" ;
23
34const usePostRequest = ( postParams ) => {
45 const { params, provider} = ! ! postParams && postParams ;
56 const [ data , setData ] = useState ( null ) ;
67 const [ isLoading , setIsLoading ] = useState ( false ) ;
78 const [ error , setError ] = useState ( "" ) ;
9+ const { userToken } = useLocalStorage ( ) ;
810
911 useEffect ( ( ) => {
1012 if ( params ) {
@@ -14,7 +16,8 @@ const usePostRequest = (postParams) => {
1416 method : "POST" ,
1517 headers : {
1618 "Content-type" : "application/json" ,
17- "Backend" : provider
19+ "Backend" : provider ,
20+ 'Authorization' : `Bearer ${ userToken } `
1821 } ,
1922 body : JSON . stringify ( params )
2023 } )
You can’t perform that action at this time.
0 commit comments