Skip to content

Commit 6d0ef19

Browse files
author
Jovert Lota Palonpon
committed
wip
1 parent f050a8b commit 6d0ef19

File tree

1 file changed

+25
-30
lines changed

1 file changed

+25
-30
lines changed

resources/js/Backoffice.js

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Component, Suspense } from 'react';
1+
import React, { Component } from 'react';
22
import { HashRouter as Router } from 'react-router-dom';
33
import { withWidth, CssBaseline, MuiThemeProvider } from '@material-ui/core';
44

@@ -35,7 +35,7 @@ class Backoffice extends Component {
3535
const response = await axios.post('/api/auth/refresh');
3636
const token = response.data;
3737

38-
this.setToken(token);
38+
await this.setToken(token);
3939

4040
this.setState(prevState => {
4141
return {
@@ -63,7 +63,7 @@ class Backoffice extends Component {
6363
const token = JSON.parse(tokenString);
6464

6565
if (token) {
66-
this.setToken(token);
66+
await this.setToken(token);
6767

6868
await this.fetchUser();
6969
}
@@ -234,8 +234,9 @@ class Backoffice extends Component {
234234
},
235235

236236
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) {
239240
this.setState({
240241
retrying: true,
241242
});
@@ -313,38 +314,32 @@ class Backoffice extends Component {
313314
const { width } = this.props;
314315
const { loading, nightMode } = this.state;
315316

316-
const renderLoading = (
317-
<Loading
318-
pageProps={{
319-
...this.state,
320-
}}
321-
/>
322-
);
323-
324317
return (
325318
<MuiThemeProvider theme={nightMode ? darkTheme : lightTheme}>
326319
<CssBaseline />
327320

328321
{loading ? (
329-
renderLoading
322+
<Loading
323+
pageProps={{
324+
...this.state,
325+
}}
326+
/>
330327
) : (
331328
<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+
/>
348343
</Router>
349344
)}
350345
</MuiThemeProvider>

0 commit comments

Comments
 (0)