diff --git a/src/components/repo/repo.ts b/src/components/repo/repo.ts index 2fc5aea..7b75d3c 100644 --- a/src/components/repo/repo.ts +++ b/src/components/repo/repo.ts @@ -33,5 +33,15 @@ export const fetchWithToken = (token: string, url: string, params: RequestInit = return value; }); -export const tokenStore = writable((localStorage.getItem("sw-session") ?? "")); -tokenStore.subscribe((value) => localStorage.setItem("sw-session", value)); +export function getLocalStorage() { + if (typeof localStorage === "undefined") { + return { + getItem: () => "", + setItem: () => {}, + }; + } + return localStorage; +} + +export const tokenStore = writable((getLocalStorage().getItem("sw-session") ?? "")); +tokenStore.subscribe((value) => getLocalStorage().setItem("sw-session", value)); diff --git a/src/components/stores/stores.ts b/src/components/stores/stores.ts index 320906c..fa0bddf 100644 --- a/src/components/stores/stores.ts +++ b/src/components/stores/stores.ts @@ -70,5 +70,8 @@ export const branches = cached([], async () => { export const server = derived(dataRepo, $dataRepo => $dataRepo.getServer()); -export const isWide = writable(window.innerWidth >= 640); -window.addEventListener("resize", () => isWide.set(window.innerWidth >= 640)); +export const isWide = writable(typeof window !== "undefined" && window.innerWidth >= 640); + +if (typeof window !== "undefined") { + window.addEventListener("resize", () => isWide.set(window.innerWidth >= 640)); +} diff --git a/src/layouts/NavbarLayout.astro b/src/layouts/NavbarLayout.astro index 17c72fc..2ce9df5 100644 --- a/src/layouts/NavbarLayout.astro +++ b/src/layouts/NavbarLayout.astro @@ -29,7 +29,7 @@ const {title, description} = Astro.props;