diff --git a/src/components/Editor.svelte b/src/components/Editor.svelte index 97e782d..9d85b0b 100644 --- a/src/components/Editor.svelte +++ b/src/components/Editor.svelte @@ -10,7 +10,7 @@ import { getCode, recoveryCode } from "../editor/utils"; import { connectLanguageServer } from "../editor/lsp"; - const ws = writable(connectLanguageServer(getUser().id)); + const ws = writable(connectLanguageServer(getUser()?.id)); settings.subscribe(async (s) => { const userId = s.config.find((c) => c.key === "User ID"); diff --git a/src/localStorage/index.ts b/src/localStorage/index.ts index c1cf40b..427bc97 100644 --- a/src/localStorage/index.ts +++ b/src/localStorage/index.ts @@ -58,24 +58,26 @@ export const visited = () => { } const user = getUser(); - settings.update((self) => { - const config = self.config.find((c) => c.key === "User ID"); - if (config) config.value = user.id; - return self; - }); + if (user) { + settings.update((self) => { + const config = self.config.find((c) => c.key === "User ID"); + if (config) config.value = user.id; + return self; + }); + } }; export const isVisited = () => { return (store.local.get(VISITED_KEY) as boolean | null) ?? false; }; -export const getUser = (): User => { +export const getUser = (): User | undefined => { const user = store.local.get(USER_KEY); return user; }; export const updateUser = (user: Partial) => { - const prevUser = getUser(); + const prevUser = getUser()!; const newUser: User = { ...prevUser, ...user }; store.local.set(USER_KEY, newUser); };