From 37e260b1bec4517071abcfc8d7dcf95e8de5d832 Mon Sep 17 00:00:00 2001 From: Charlie Tonneslan Date: Sun, 17 May 2026 19:19:31 -0400 Subject: [PATCH] Send logged-out users to login when clicking Follow The Follow buttons on the testimony detail page (and elsewhere) silently no-op'd if a logged-out visitor clicked them: the underlying setDoc runs against /users/undefined/... and Firestore rules reject it. Push the visitor through the same /login?redirect= flow other auth-gated actions use so they end up back on the page they were on. Closes #2059 Signed-off-by: Charlie Tonneslan --- components/shared/FollowButton.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/components/shared/FollowButton.tsx b/components/shared/FollowButton.tsx index f6d5c236b..b094bf283 100644 --- a/components/shared/FollowButton.tsx +++ b/components/shared/FollowButton.tsx @@ -1,4 +1,5 @@ import { StyledImage } from "components/ProfilePage/StyledProfileComponents" +import { useRouter } from "next/router" import { useTranslation } from "next-i18next" import { useEffect, useContext, useMemo, useState } from "react" import { Button } from "react-bootstrap" @@ -88,6 +89,7 @@ export const BaseFollowButton = ({ }) => { const { t } = useTranslation("common") const uid = useAuth().user?.uid + const router = useRouter() const { followStatus, setFollowStatus } = useContext(FollowContext) const [modalAction, setModalAction] = useState<"follow" | "unfollow" | null>( null @@ -111,9 +113,12 @@ export const BaseFollowButton = ({ } const isFollowing = followStatus[topicName] - const onClick = isFollowing - ? () => (confirmUnfollow ? setModalAction("unfollow") : UnfollowClick()) - : () => (confirmFollow ? setModalAction("follow") : FollowClick()) + const onClick = !uid + ? () => + router.push(`/login?redirect=${encodeURIComponent(router.asPath)}`) + : isFollowing + ? () => (confirmUnfollow ? setModalAction("unfollow") : UnfollowClick()) + : () => (confirmFollow ? setModalAction("follow") : FollowClick()) return ( <>