fix(frontend): refresh guild tokens on mount to avoid stale-token 401

Guild access tokens (15-min TTL) are persisted in localStorage but were
never refreshed on page (re)load - only the center token was. After the
TTL elapsed, GET /channels failed with 401 ('Failed to load channels').
Re-issue guild tokens via refreshGuilds() on mount and reload channels
when the guild token changes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
h z
2026-05-15 09:14:10 +01:00
parent 6b35d92aef
commit 1b70f27fc4

View File

@@ -42,6 +42,14 @@ export default function ChatPage() {
if (!selectedGuildId && guilds.length) setSelectedGuildId(guilds[0].nodeId)
}, [guilds, selectedGuildId])
// Guild access tokens have a short TTL and are persisted in localStorage.
// On (re)load they may be expired, so re-issue fresh ones from Center
// before any guild API call. refreshGuilds also refreshes the center token.
useEffect(() => {
refreshGuilds().catch(() => {})
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
const guild = useMemo(() => guilds.find((g) => g.nodeId === selectedGuildId) ?? null, [guilds, selectedGuildId])
const guildToken = useMemo(
() => (session?.guildAccessTokens ?? []).find((x) => x.guildNodeId === selectedGuildId)?.token ?? '',
@@ -196,7 +204,7 @@ export default function ChatPage() {
void loadChannels()
setMessages([])
setSelectedChannelId('')
}, [selectedGuildId, guildDbId])
}, [selectedGuildId, guildDbId, guildToken])
useEffect(() => {
void pullMessages()