From 0ab6cf0ff095209f0a4d83c4295ecd5558de8a89 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 10 Aug 2023 02:11:50 -0400 Subject: [PATCH] fix: handle localStorage being undefined --- src/portal.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/portal.ts b/src/portal.ts index 1cd1404..40f6fae 100644 --- a/src/portal.ts +++ b/src/portal.ts @@ -120,11 +120,17 @@ export function savePortals() { url: item.portalUrl, } as Portal; }); - window.localStorage.setItem("portals", JSON.stringify(portals)); + if (typeof globalThis.localStorage !== "undefined") { + globalThis.localStorage.setItem("portals", JSON.stringify(portals)); + } } export function loadSavedPortals(): Portal[] | null { - let portals = window.localStorage.getItem("portals"); + let portals: string | null = null; + + if (typeof globalThis.localStorage !== "undefined") { + portals = globalThis.localStorage.getItem("portals"); + } if (!portals) { return null;