Skip to content

Commit

Permalink
frontend/charger_list: refresh jwt token when receiving status 401 wh…
Browse files Browse the repository at this point in the history
…ile getting the charger-list. This enables the page to recover from breakning although it still shows an error. Part of #88
  • Loading branch information
ffreddow committed Dec 3, 2024
1 parent 33348f7 commit d5677a2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions frontend/src/components/charger_list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useTranslation } from "react-i18next";
import { showAlert } from "../components/Alert";
import { Base64 } from "js-base64";
import { Component } from "preact";
import { fetchClient } from "../utils";
import { fetchClient, refresh_access_token } from "../utils";
import { Button, ButtonGroup, Card, Col, Container, Dropdown, DropdownButton, Modal, Row, Table } from "react-bootstrap";
import i18n from "../i18n";
import { ChevronDown, ChevronUp, Minus, Monitor, Trash2 } from "react-feather";
Expand Down Expand Up @@ -90,7 +90,12 @@ export class ChargerListComponent extends Component<{}, ChargerListComponentStat
if (!secret) {
await that.get_decrypted_secret();
}
fetchClient.GET("/charger/get_chargers", {credentials: "same-origin"}).then(async ({data}) => {
fetchClient.GET("/charger/get_chargers", {credentials: "same-origin"}).then(async ({data, response}) => {
if (response.status === 401) {
await refresh_access_token();
this.updateChargers;
return;
}
const chargers: Charger[] = data;
const state_chargers = [];
for (const charger of chargers) {
Expand Down Expand Up @@ -372,7 +377,7 @@ export class ChargerListComponent extends Component<{}, ChargerListComponentStat
{this.get_icon("note")}
</Col>
</Row>
</th>
</th>
<th />
<th />
</tr>
Expand Down

0 comments on commit d5677a2

Please sign in to comment.