source: frontend/src/index.js@ badbc79

Last change on this file since badbc79 was badbc79, checked in by Luka Cheshlarov <luka.cheshlarov@…>, 20 months ago

Initial commit

  • Property mode set to 100644
File size: 1.5 KB
Line 
1import React from 'react';
2import ReactDOM from 'react-dom/client';
3import './index.css';
4import reportWebVitals from './reportWebVitals';
5import {redirect} from "react-router-dom";
6
7import 'bootstrap/dist/css/bootstrap.min.css';
8import 'react-toastify/dist/ReactToastify.css';
9
10import axios from "axios";
11import {AuthProvider} from "./configurations/AuthContext";
12import {toast} from "react-toastify";
13import App from "./App";
14
15const credentials = JSON.parse(sessionStorage.getItem("authData"));
16
17axios.defaults.baseURL = 'http://localhost:8080/api';
18axios.defaults.headers.post['Content-Type'] = 'application/json';
19if (credentials) {
20 axios.defaults.headers.common['Authorization'] = credentials.userCredential;
21}
22
23axios.interceptors.response.use((response) => {
24 if (response.config.method !== "get") {
25 toast.success("Success", {
26 toastId: "custom-id-success"
27 })
28 }
29 return response;
30}, function (error) {
31 console.log(error);
32 toast.error(error.message)
33
34 if (error.response.status === 404) {
35 redirect('/');
36 }
37 return Promise.reject(error.response);
38});
39
40
41
42
43const root = ReactDOM.createRoot(document.getElementById('root'));
44root.render(
45 <AuthProvider>
46 <App/>
47 </AuthProvider>
48);
49
50// If you want to start measuring performance in your app, pass a function
51// to log results (for example: reportWebVitals(console.log))
52// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
53reportWebVitals();
Note: See TracBrowser for help on using the repository browser.