refactor(auth): unify current user state usage across UI

This commit is contained in:
zetaloop
2026-02-22 08:03:09 +08:00
parent 7bcb73f139
commit 312061330c
8 changed files with 47 additions and 44 deletions
+4 -4
View File
@@ -2,7 +2,7 @@
import { Heart } from "lucide-react"
import { useState } from "react"
import { currentUser } from "@/lib/mock"
import { generateId } from "@/lib/id"
import type { Comment } from "@/lib/types"
import { useRequireAuth } from "@/lib/use-require-auth"
import { useAuthStore } from "@/store/auth"
@@ -32,14 +32,14 @@ export function PostComments({ initialComments, postId }: PostCommentsProps) {
requireAuth(() => {
const nextContent = content.trim()
if (!nextContent) return
const author = user ?? currentUser
if (!user) return
const createdAt = new Date().toISOString()
setComments((prev) => [
...prev,
{
id: `comment-${postId}-${createdAt}`,
id: generateId(`comment-${postId}`),
postId,
author,
author: user,
content: nextContent,
likeCount: 0,
liked: false,