refactor: Update loggedIn store type and streamline login/dashboard navigation logic
Some checks failed
SteamWarCI Build failed
Some checks failed
SteamWarCI Build failed
This commit is contained in:
@@ -89,6 +89,6 @@ export class AuthV2Repo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const loggedIn = writable(false);
|
export const loggedIn = writable<boolean | undefined>(undefined);
|
||||||
|
|
||||||
export const authV2Repo = readable(new AuthV2Repo());
|
export const authV2Repo = readable(new AuthV2Repo());
|
||||||
|
|||||||
@@ -1,22 +1,21 @@
|
|||||||
---
|
---
|
||||||
import DashboardComponent from "@components/DashboardComponent.svelte";
|
import DashboardComponent from "@components/DashboardComponent.svelte";
|
||||||
import PageLayout from "@layouts/PageLayout.astro";
|
import PageLayout from "@layouts/PageLayout.astro";
|
||||||
import {t} from "astro-i18n";
|
import { t } from "astro-i18n";
|
||||||
---
|
---
|
||||||
|
|
||||||
<PageLayout title={t("dashboard.page")}>
|
<PageLayout title={t("dashboard.page")}>
|
||||||
<script>
|
<script is:inline data-astro-rerun>
|
||||||
import {l} from "../util/util";
|
import { l } from "../util/util";
|
||||||
import {navigate} from "astro:transitions/client";
|
import { navigate } from "astro:transitions/client";
|
||||||
import {get} from "svelte/store";
|
import { loggedIn } from "../components/repo/authv2";
|
||||||
import {loggedIn} from "../components/repo/authv2";
|
loggedIn.subscribe((value) => {
|
||||||
document.addEventListener("astro:page-load", () => {
|
|
||||||
if (window.location.href.endsWith("/dashboard") || window.location.href.endsWith("/dashboard/")) {
|
if (window.location.href.endsWith("/dashboard") || window.location.href.endsWith("/dashboard/")) {
|
||||||
if (!get(loggedIn)) {
|
if (value === false) {
|
||||||
navigate(l("/login"), {});
|
navigate(l("/dashboard"), { history: "replace" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<DashboardComponent client:only="svelte" />
|
<DashboardComponent client:only="svelte" />
|
||||||
</PageLayout>
|
</PageLayout>
|
||||||
|
|||||||
@@ -6,15 +6,14 @@ import BackgroundImage from "../components/BackgroundImage.astro";
|
|||||||
---
|
---
|
||||||
|
|
||||||
<NavbarLayout title={t("login.page")}>
|
<NavbarLayout title={t("login.page")}>
|
||||||
<script>
|
<script is:inline data-astro-rerun>
|
||||||
import { l } from "../util/util";
|
import { l } from "../util/util";
|
||||||
import { navigate } from "astro:transitions/client";
|
import { navigate } from "astro:transitions/client";
|
||||||
import { loggedIn } from "../components/repo/authv2";
|
import { loggedIn } from "../components/repo/authv2";
|
||||||
import { get } from "svelte/store";
|
|
||||||
|
|
||||||
document.addEventListener("astro:page-load", () => {
|
loggedIn.subscribe((value) => {
|
||||||
if (window.location.href.endsWith("/login") || window.location.href.endsWith("/login/")) {
|
if (window.location.href.endsWith("/login") || window.location.href.endsWith("/login/")) {
|
||||||
if (get(loggedIn)) {
|
if (value) {
|
||||||
navigate(l("/dashboard"), { history: "replace" });
|
navigate(l("/dashboard"), { history: "replace" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user