Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect on login page when token expires #1539

Merged
merged 2 commits into from
Jul 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo, should be cancelled.

}
}
});
}

render() {
Expand Down
Loading