feat: add auth guards to protected routes and extend requireAuth coverage
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user