feat: add auth guards to protected routes and extend requireAuth coverage

This commit is contained in:
zetaloop
2026-02-20 22:38:29 +08:00
parent c0896faa78
commit 4cc4383603
6 changed files with 63 additions and 4 deletions
+7
View File
@@ -20,6 +20,7 @@ import {
SelectValue,
} from "@/components/ui/select"
import { Textarea } from "@/components/ui/textarea"
import { useRequireAuth } from "@/lib/use-require-auth"
const postSchema = z.object({
title: z.string().min(2, "标题至少2个字符").max(50, "标题最多50个字符"),
@@ -30,6 +31,7 @@ const tagOptions = ["英雄联盟", "王者荣耀", "CS2", "原神", "上分", "
export default function NewPostPage() {
const router = useRouter()
const { isAuthenticated, requireAuth } = useRequireAuth()
const [postType, setPostType] = useState("normal")
const [selectedTags, setSelectedTags] = useState<string[]>([])
const [imageCount, setImageCount] = useState(0)
@@ -49,6 +51,11 @@ export default function NewPostPage() {
}
const onSubmit = async () => {
if (!isAuthenticated) {
requireAuth(() => undefined)
return
}
await new Promise((r) => setTimeout(r, 500))
router.push("/community")
}