diff --git a/apps/manacore/apps/web/src/lib/modules/contacts/stores/contacts.svelte.ts b/apps/manacore/apps/web/src/lib/modules/contacts/stores/contacts.svelte.ts index ab17656b9..a598bd115 100644 --- a/apps/manacore/apps/web/src/lib/modules/contacts/stores/contacts.svelte.ts +++ b/apps/manacore/apps/web/src/lib/modules/contacts/stores/contacts.svelte.ts @@ -115,9 +115,10 @@ export const contactsStore = { /** * Ensure the self-contact exists and is synced with the user's profile. * Creates the contact if missing, updates it if profile data changed. + * Works without profile data (guest mode) — creates a minimal self-contact. */ - async ensureSelfContact(profile: UserProfile): Promise { - const nameParts = (profile.name || '').split(' '); + async ensureSelfContact(profile?: UserProfile | null): Promise { + const nameParts = (profile?.name || '').split(' '); const firstName = nameParts[0] || undefined; const lastName = nameParts.slice(1).join(' ') || undefined; @@ -126,10 +127,10 @@ export const contactsStore = { if (!existing) { const self: LocalContact = { id: SELF_CONTACT_ID, - firstName, + firstName: firstName || 'Ich', lastName, - email: profile.email || undefined, - photoUrl: profile.image || undefined, + email: profile?.email || undefined, + photoUrl: profile?.image || undefined, isFavorite: true, isArchived: false, createdAt: new Date().toISOString(), @@ -139,7 +140,9 @@ export const contactsStore = { return; } - // Sync profile fields if they changed + // Only sync if we have profile data + if (!profile) return; + const needsUpdate = existing.firstName !== firstName || existing.lastName !== lastName || diff --git a/apps/manacore/apps/web/src/routes/(app)/contacts/+layout.svelte b/apps/manacore/apps/web/src/routes/(app)/contacts/+layout.svelte index 4094686ce..f413b0df5 100644 --- a/apps/manacore/apps/web/src/routes/(app)/contacts/+layout.svelte +++ b/apps/manacore/apps/web/src/routes/(app)/contacts/+layout.svelte @@ -20,13 +20,15 @@ // Ensure self-contact exists and stays synced with profile onMount(async () => { - if (!authStore.isAuthenticated) return; - try { - const profile = await profileService.getProfile(); - await contactsStore.ensureSelfContact(profile); - } catch { - // Profile fetch may fail for guest users — that's OK + let profile = null; + if (authStore.isAuthenticated) { + try { + profile = await profileService.getProfile(); + } catch { + // Profile fetch may fail — continue with guest self-contact + } } + await contactsStore.ensureSelfContact(profile); });