feat(todo): wire up browser sync with Go server

- Auth store starts/stops sync on login/logout
- LocalStore queues all existing records for initial sync (guest→auth transition)
- LocalCollection.queueAllForSync() creates pending inserts for all local records
- Skips initial queue if sync cursor exists (already synced before)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Till JS 2026-03-27 11:50:43 +01:00
parent 8f56feb115
commit b85c32fcce
3 changed files with 62 additions and 1 deletions

View file

@ -6,6 +6,7 @@
import { browser } from '$app/environment';
import { initializeWebAuth, type UserData } from '@manacore/shared-auth';
import { apiClient } from '$lib/api/client';
import { todoStore } from '$lib/data/local-store';
// Default URLs for local development only
const DEV_AUTH_URL = 'http://localhost:3001';
@ -221,6 +222,9 @@ export const authStore = {
apiClient.setAccessToken(token);
}
// Start syncing local data to server
todoStore.startSync(() => authStore.getValidToken());
return { success: true };
} catch (error) {
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
@ -264,6 +268,9 @@ export const authStore = {
* Sign out
*/
async signOut() {
// Stop syncing before clearing auth
todoStore.stopSync();
const authService = getAuthService();
if (!authService) {
user = null;