diff --git a/notes-workspace.html b/notes-workspace.html index 9071c3f..109d562 100644 --- a/notes-workspace.html +++ b/notes-workspace.html @@ -504,6 +504,29 @@ writeOutput({ message: 'PocketBase session cleared.' }); } + async function bootstrapWorkspace() { + try { + const client = await ensurePocketBaseClient(); + const config = await getPocketBaseConfig(); + + if (client.authStore?.token) { + try { + await client.collection(config.collection).authRefresh(); + } catch { + } + } + + await updatePbStatus(); + if (client.authStore?.isValid) { + await loadNotes(); + } else { + writeOutput('Login to load notes.'); + } + } catch (error) { + writeOutput({ error: error?.message || String(error) }); + } + } + async function loadNotes() { await ensurePocketBaseClient(); ensureLoggedIn(); @@ -614,9 +637,7 @@ searchInput.addEventListener('input', () => renderList()); hiddenMode.addEventListener('change', () => renderList()); - ensurePocketBaseClient() - .then(() => updatePbStatus()) - .catch((error) => writeOutput({ error: error?.message || String(error) })); + bootstrapWorkspace(); clearForm(); renderList(); loadHealth();