Authenticate over NIP-42 so members see hidden rooms + use one shared SimplePool

This commit is contained in:
dtonon 2026-06-09 13:00:46 +01:00
parent 6377d00268
commit d965cdef01
17 changed files with 251 additions and 204 deletions

View file

@ -22,6 +22,7 @@
import { loadRoomAdmins } from "$lib/admins.svelte";
import { seedProfiles } from "$lib/profiles.svelte";
import { startChat } from "$lib/chat.svelte";
import { resetForumConnection } from "$lib/relay";
import { activeGroup, setActiveGroup } from "$lib/active.svelte";
import { MODE, ACCENT_COLOR, SECONDARY_COLOR } from "$lib/config";
@ -72,6 +73,30 @@
seedProfiles(auth.user?.pubkey ?? null);
});
// Reload the room views when the user logs in or out: a logged-in member sees
// their private/hidden rooms, so the listing must be re-fetched over the now
// (de)authenticated connection. sessionEpoch only bumps on explicit
// login/logout, never on the silent restore that onMount already covers.
let lastEpoch = -1;
$effect(() => {
const epoch = auth.sessionEpoch;
if (epoch === lastEpoch) return;
const first = lastEpoch === -1;
const loggedOut = auth.user === null;
lastEpoch = epoch;
if (first) return; // initial mount: onMount already loaded everything
// On logout, drop the authenticated connection so the relay stops serving
// the previous user's private rooms; login reuses the open connection,
// which ensureForumReady authenticates via its stored challenge.
if (loggedOut) resetForumConnection();
loadGroup();
if (mode === "full") {
loadGroups().then(() =>
loadRoomAdmins(groupsStore.list.map((g) => g.id)),
);
}
});
// Full mode: the room route defines the active group. Thread pages set it
// themselves from the thread's own group, so only track the slug here.
$effect(() => {