diff --git a/apps/web/src/routes/_authenticated/$guildSlug/$channelId.tsx b/apps/web/src/routes/_authenticated/$guildSlug/$channelId.tsx index 6eca626..db9634f 100644 --- a/apps/web/src/routes/_authenticated/$guildSlug/$channelId.tsx +++ b/apps/web/src/routes/_authenticated/$guildSlug/$channelId.tsx @@ -40,7 +40,14 @@ function ChannelView() { const currentUserId = session?.user.id useEffect(() => { - localStorage.setItem(`last-channel:${guildSlug}`, channelId) + if (!guildSlug || !channelId) return + try { + if (typeof window !== "undefined") { + localStorage.setItem(`last-channel:${guildSlug}`, channelId) + } + } catch { + // localStorage may be unavailable in restricted environments + } }, [guildSlug, channelId]) useEffect(() => { diff --git a/apps/web/src/routes/_authenticated/$guildSlug/index.tsx b/apps/web/src/routes/_authenticated/$guildSlug/index.tsx index 58ffb0e..c3d1c1e 100644 --- a/apps/web/src/routes/_authenticated/$guildSlug/index.tsx +++ b/apps/web/src/routes/_authenticated/$guildSlug/index.tsx @@ -10,7 +10,14 @@ function GuildHome() { const navigate = useNavigate() useEffect(() => { - const lastChannelId = localStorage.getItem(`last-channel:${guildSlug}`) + let lastChannelId: string | null = null + try { + if (typeof window !== "undefined") { + lastChannelId = localStorage.getItem(`last-channel:${guildSlug}`) + } + } catch { + // localStorage may be unavailable in restricted environments + } if (lastChannelId) { void navigate({ to: "/$guildSlug/$channelId",