|
|
@ -1,10 +1,12 @@ |
|
|
|
import { WebSocketRpcClient } from "@app/sprinklersRpc/websocketClient"; |
|
|
|
|
|
|
|
import HttpApi from "@app/state/HttpApi"; |
|
|
|
|
|
|
|
import { UiStore } from "@app/state/UiStore"; |
|
|
|
|
|
|
|
import { createBrowserHistory, History } from "history"; |
|
|
|
import { createBrowserHistory, History } from "history"; |
|
|
|
import { computed } from "mobx"; |
|
|
|
import { computed } from "mobx"; |
|
|
|
import { RouterStore, syncHistoryWithStore } from "mobx-react-router"; |
|
|
|
import { RouterStore, syncHistoryWithStore } from "mobx-react-router"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { WebSocketRpcClient } from "@app/sprinklersRpc/websocketClient"; |
|
|
|
|
|
|
|
import HttpApi from "@app/state/HttpApi"; |
|
|
|
|
|
|
|
import { UiStore } from "@app/state/UiStore"; |
|
|
|
|
|
|
|
import log from "@common/logger"; |
|
|
|
|
|
|
|
|
|
|
|
const isDev = process.env.NODE_ENV === "development"; |
|
|
|
const isDev = process.env.NODE_ENV === "development"; |
|
|
|
const websocketPort = isDev ? 8080 : location.port; |
|
|
|
const websocketPort = isDev ? 8080 : location.port; |
|
|
|
|
|
|
|
|
|
|
@ -28,7 +30,13 @@ export default class AppState { |
|
|
|
|
|
|
|
|
|
|
|
if (!this.httpApi.tokenStore.accessToken.isValid) { |
|
|
|
if (!this.httpApi.tokenStore.accessToken.isValid) { |
|
|
|
if (this.httpApi.tokenStore.refreshToken.isValid) { |
|
|
|
if (this.httpApi.tokenStore.refreshToken.isValid) { |
|
|
|
await this.httpApi.tokenStore.grantRefresh(); |
|
|
|
try { |
|
|
|
|
|
|
|
await this.httpApi.tokenStore.grantRefresh(); |
|
|
|
|
|
|
|
} catch (err) { |
|
|
|
|
|
|
|
log.warn({ err }, "could not refresh access token. erasing token"); |
|
|
|
|
|
|
|
this.tokenStore.clear(); |
|
|
|
|
|
|
|
this.history.push("/login"); |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.history.push("/login"); |
|
|
|
this.history.push("/login"); |
|
|
|
} |
|
|
|
} |
|
|
|