diff --git a/pages/_app.tsx b/pages/_app.tsx index 75ffb8d..0ad1eaf 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -9,18 +9,36 @@ import { StaticImageData } from 'next/image' import { appWithTranslation } from 'next-i18next' import { FestaLoginData } from '../types/user' import {useStoredLogin} from "../hooks/useStoredLogin" +import { Fetcher, SWRConfig } from 'swr' +import axios, { AxiosRequestConfig } from 'axios' const App = ({ Component, pageProps }: AppProps): JSX.Element => { - const [login, setLogin] = useState(null) const [postcard, setPostcard] = useState(defaultPostcard) + + const [login, setLogin] = useState(null) useStoredLogin(setLogin) + const axiosConfig = { + headers: { + "Authorization": login ? `Bearer ${login.token}` : "", + } + } + + const swrConfig = { + fetcher: async (resource: string, localAxiosConfig: AxiosRequestConfig) => { + const response = await axios.get(resource, {...axiosConfig, ...localAxiosConfig}) + return response.data + } + } + return ( + + )