fixed redirect on session expired

This commit is contained in:
Sean Macfarlane
2020-06-04 18:04:00 -04:00
parent 776b9a68f1
commit 357cbb69ca
4 changed files with 770 additions and 227 deletions

View File

@@ -1,6 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router } from 'react-router-dom';
import { Router } from 'react-router-dom';
import ApolloClient from 'apollo-boost';
import { ApolloProvider } from '@apollo/react-hooks';
import gql from 'graphql-tag';
@@ -12,6 +12,7 @@ import App from 'containers/App';
import { AUTH_TOKEN } from 'constants/index';
import { getItem, setItem, removeItem } from 'utils/localStorage';
import history from 'utils/history';
const API_URI = process.env.NODE_ENV !== 'production' ? 'http://localhost:4000/' : '';
const MOUNT_NODE = document.getElementById('root');
@@ -63,6 +64,7 @@ const client = new ApolloClient({
case 'INTERNAL_SERVER_ERROR':
if (err.path && err.path[0] === 'updateToken') {
removeItem(AUTH_TOKEN);
history.push('/login');
}
return forward(operation);
default:
@@ -75,7 +77,7 @@ const client = new ApolloClient({
const render = () => {
ReactDOM.render(
<Router>
<Router history={history}>
<ApolloProvider client={client}>
<App />
</ApolloProvider>

3
app/utils/history.js Normal file
View File

@@ -0,0 +1,3 @@
import { createBrowserHistory } from 'history';
export default createBrowserHistory();

983
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -17,15 +17,16 @@
},
"license": "MIT",
"dependencies": {
"@ant-design/icons": "^4.0.2",
"@ant-design/icons": "^4.2.1",
"@apollo/react-hoc": "^3.1.4",
"@apollo/react-hooks": "^3.1.3",
"@tip-wlan/wlan-cloud-ui-library": "^0.1.3",
"antd": "^4.2.2",
"antd": "^4.3.1",
"apollo-boost": "^0.4.7",
"clean-webpack-plugin": "^3.0.0",
"graphql": "^14.6.0",
"graphql-tag": "^2.10.3",
"history": "^4.10.1",
"html-webpack-plugin": "^3.2.0",
"lodash": "^4.17.15",
"mini-css-extract-plugin": "^0.9.0",