Skip to content

Commit

Permalink
fix(ui): redirect on login page when token expires (#1539)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisSouquiere committed Jul 31, 2023
1 parent f8c8a06 commit 0519dbc
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion client/src/App.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,32 @@
import React from 'react';
import { BrowserRouter as Router } from 'react-router-dom';
import { basePath } from './utils/endpoints';
import { basePath, uriLogin } from './utils/endpoints';
import Routes from './utils/Routes';
import { MuiPickersUtilsProvider } from '@material-ui/pickers';
import MomentUtils from '@date-io/moment';
import { ToastContainer } from 'react-toastify';
import { loadProgressBar } from 'axios-progress-bar';
import axios from 'axios';

class App extends React.Component {
componentDidMount() {
loadProgressBar();

axios.interceptors.response.use(null, error => {
try {
// Used for token expiration by redirecting on login page
if (error.response.status === 401) {
window.location = uriLogin();
}

return error;
} catch (e) {
// Propagate cancel
if (axios.isCancel(error)) {
throw new axios.Cancel('Operation canceled by the user.');
}
}
});
}

render() {
Expand Down

0 comments on commit 0519dbc

Please sign in to comment.