|
1 |
| -import React, { Component, Suspense } from 'react'; |
| 1 | +import React, { Component } from 'react'; |
2 | 2 | import { HashRouter as Router } from 'react-router-dom';
|
3 | 3 | import { withWidth, CssBaseline, MuiThemeProvider } from '@material-ui/core';
|
4 | 4 |
|
@@ -35,7 +35,7 @@ class Backoffice extends Component {
|
35 | 35 | const response = await axios.post('/api/auth/refresh');
|
36 | 36 | const token = response.data;
|
37 | 37 |
|
38 |
| - this.setToken(token); |
| 38 | + await this.setToken(token); |
39 | 39 |
|
40 | 40 | this.setState(prevState => {
|
41 | 41 | return {
|
@@ -63,7 +63,7 @@ class Backoffice extends Component {
|
63 | 63 | const token = JSON.parse(tokenString);
|
64 | 64 |
|
65 | 65 | if (token) {
|
66 |
| - this.setToken(token); |
| 66 | + await this.setToken(token); |
67 | 67 |
|
68 | 68 | await this.fetchUser();
|
69 | 69 | }
|
@@ -234,8 +234,9 @@ class Backoffice extends Component {
|
234 | 234 | },
|
235 | 235 |
|
236 | 236 | async error => {
|
237 |
| - // In occasions of Unauthorized requests, retry. |
238 |
| - if (error.response.status === 401) { |
| 237 | + // In occasions of Unauthorized requests (401), |
| 238 | + // Retry (if authenticated earlier). |
| 239 | + if (error.response.status === 401 && this.state.authenticated) { |
239 | 240 | this.setState({
|
240 | 241 | retrying: true,
|
241 | 242 | });
|
@@ -313,38 +314,32 @@ class Backoffice extends Component {
|
313 | 314 | const { width } = this.props;
|
314 | 315 | const { loading, nightMode } = this.state;
|
315 | 316 |
|
316 |
| - const renderLoading = ( |
317 |
| - <Loading |
318 |
| - pageProps={{ |
319 |
| - ...this.state, |
320 |
| - }} |
321 |
| - /> |
322 |
| - ); |
323 |
| - |
324 | 317 | return (
|
325 | 318 | <MuiThemeProvider theme={nightMode ? darkTheme : lightTheme}>
|
326 | 319 | <CssBaseline />
|
327 | 320 |
|
328 | 321 | {loading ? (
|
329 |
| - renderLoading |
| 322 | + <Loading |
| 323 | + pageProps={{ |
| 324 | + ...this.state, |
| 325 | + }} |
| 326 | + /> |
330 | 327 | ) : (
|
331 | 328 | <Router>
|
332 |
| - <Suspense fallback={renderLoading}> |
333 |
| - <Navigator |
334 |
| - pageProps={{ |
335 |
| - ...this.state, |
336 |
| - width, |
337 |
| - environment: 'backoffice', |
338 |
| - routes: ROUTES, |
339 |
| - handleNightmodeToggled: this |
340 |
| - .handleNightmodeToggled, |
341 |
| - refresh: this.refresh, |
342 |
| - authenticate: this.authenticate, |
343 |
| - handleLock: this.handleLock, |
344 |
| - handleSignout: this.handleSignout, |
345 |
| - }} |
346 |
| - /> |
347 |
| - </Suspense> |
| 329 | + <Navigator |
| 330 | + pageProps={{ |
| 331 | + ...this.state, |
| 332 | + width, |
| 333 | + environment: 'backoffice', |
| 334 | + routes: ROUTES, |
| 335 | + handleNightmodeToggled: this |
| 336 | + .handleNightmodeToggled, |
| 337 | + refresh: this.refresh, |
| 338 | + authenticate: this.authenticate, |
| 339 | + handleLock: this.handleLock, |
| 340 | + handleSignout: this.handleSignout, |
| 341 | + }} |
| 342 | + /> |
348 | 343 | </Router>
|
349 | 344 | )}
|
350 | 345 | </MuiThemeProvider>
|
|
0 commit comments