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 ( <>