Skip to content
This repository has been archived by the owner on Jan 4, 2025. It is now read-only.

Commit

Permalink
fix(web): prevent reloading on clear
Browse files Browse the repository at this point in the history
  • Loading branch information
Vexcited committed Mar 14, 2024
1 parent 8da8caf commit c510a41
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
8 changes: 7 additions & 1 deletion packages/website/src/client/clear.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { SafeStorage } from "../utils/safeStorage";
import { setStore } from "../store";

export const clearUserData = async (shouldExplicitlyClearCredentials: boolean): Promise<void> => {
if (shouldExplicitlyClearCredentials) await fetch("/api/clear-credentials", { method: "GET" });
SafeStorage.clear();
location.reload();

setStore({
dumpFromAuthentication: false,
authenticated: false,
dump: null
});
};
1 change: 1 addition & 0 deletions packages/website/src/routes/api/dump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const GET: APIHandler = async ({ nativeEvent }) => {
});
}
catch (error) {
console.error(error);
if (error instanceof WebVPNWrongCredentials) {
return createLogoutResponse(nativeEvent);
}
Expand Down
12 changes: 9 additions & 3 deletions packages/website/src/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { onMount, Show, For, createSignal } from "solid-js";

import { useNavigate } from "@solidjs/router";
import { setStore, store } from "../store";
import { createDump } from "../client/dump";
import Semester from "../components/Semester";
Expand All @@ -10,6 +10,8 @@ import { SafeStorage } from "../utils/safeStorage";
import toast from "solid-toast";

export default function Home() {
const navigate = useNavigate();

/** `null` when not selected yet. */
const [_selectedSemester, _setSelectedSemester] = createSignal(SafeStorage.getItem("selectedSemester"));
/** Helper function that also stores in the localStorage to keep preference on reload. */
Expand All @@ -34,7 +36,8 @@ export default function Home() {
const dump = await createDump();

if (dump.status === 403) {
clearUserData(false);
await clearUserData(false);
navigate("/authenticate");
return;
}
else if (dump.status !== 200) {
Expand Down Expand Up @@ -72,7 +75,10 @@ export default function Home() {
</div>

<button class="text-sm opacity-50 hover:opacity-100 px-3 py-1 bg-[rgb(240,240,240)] text-[rgb(20,20,20)] rounded-lg"
onClick={() => clearUserData(true)}
onClick={async () => {
await clearUserData(true)
navigate("/authenticate");
}}
>
Effacer toutes les données
</button>
Expand Down

0 comments on commit c510a41

Please sign in to comment.