Skip to content

Commit 98919a9

Browse files
committed
fix: forward unauthenticated viewers to login when trying to vote
1 parent 0a3e497 commit 98919a9

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

app/lib/feed-item.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,16 @@ function VoteButtons(props: {
8282
<div className="flex flex-col self-center mr-3 pb-8">
8383
<button
8484
onClick={async () => {
85-
if (props.post.upVoteByViewer?.totalCount === 0) {
85+
if (!user) {
86+
router.push("/login");
87+
} else if (props.post.upVoteByViewer?.totalCount === 0) {
8688
await deleteVote({
8789
postId: props.post.id,
88-
profileId: user!.id,
90+
profileId: user.id,
8991
});
9092
vote({
9193
postId: props.post.id,
92-
profileId: user!.id,
94+
profileId: user.id,
9395
voteDirection: "UP",
9496
});
9597
}
@@ -101,14 +103,16 @@ function VoteButtons(props: {
101103
</button>
102104
<button
103105
onClick={async () => {
104-
if (props.post.downVoteByViewer?.totalCount === 0) {
106+
if (!user) {
107+
router.push("/login");
108+
} else if (props.post.downVoteByViewer?.totalCount === 0) {
105109
await deleteVote({
106110
postId: props.post.id,
107-
profileId: user!.id,
111+
profileId: user.id,
108112
});
109113
vote({
110114
postId: props.post.id,
111-
profileId: user!.id,
115+
profileId: user.id,
112116
voteDirection: "DOWN",
113117
});
114118
}

0 commit comments

Comments
 (0)