diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-12-21 19:46:12 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2022-12-21 19:46:12 +0530 |
commit | 5d2f49c1332c78b124af33aebbfba93b7b5d9546 (patch) | |
tree | 35335ee104a0c25c864e0cecc6ef32b76b7a8bc1 /src | |
parent | a35176afd7873a317af8b4d3844037ea0233776f (diff) |
redirecting when refresh token expires
Diffstat (limited to 'src')
-rw-r--r-- | src/index.js | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/index.js b/src/index.js index 2a7a75d..d620e5d 100644 --- a/src/index.js +++ b/src/index.js @@ -2,6 +2,7 @@ import React from 'react'; import ReactDOM from 'react-dom/client'; import App from './App'; import axios from 'axios'; +import { BrowserRouter } from "react-router-dom"; // For GET requests axios.interceptors.request.use( @@ -22,8 +23,12 @@ axios.interceptors.request.use( }) .then((res) => res.json()) .then((res) => { - localStorage.setItem("accessToken", res.accessToken); - return axios(err.config); + if (res.accessToken && res.accessToken !== "") { + localStorage.setItem("accessToken", res.accessToken); + return axios(err.config); + } else { + window.location = "/login" + } }) resolve(response); } else { @@ -51,8 +56,12 @@ axios.interceptors.response.use( }) .then((res) => res.json()) .then((res) => { - localStorage.setItem("accessToken", res.accessToken); - return axios(err.config); + if (res.accessToken && res.accessToken !== "") { + localStorage.setItem("accessToken", res.accessToken); + return axios(err.config); + } else { + window.location = "/login" + } }) resolve(response); } else { @@ -61,9 +70,13 @@ axios.interceptors.response.use( }) ); +axios.defaults.baseURL = "/"; + const root = ReactDOM.createRoot(document.getElementById('root')); root.render( <React.StrictMode> - <App /> + <BrowserRouter> + <App /> + </BrowserRouter> </React.StrictMode> ); |