fix: sync verification state with auth guards

This commit is contained in:
zetaloop
2026-02-21 15:53:46 +08:00
parent 6469811382
commit 6ed8620ca6
5 changed files with 70 additions and 7 deletions
+15 -3
View File
@@ -16,9 +16,14 @@ import {
} from "@/components/ui/select"
import { Separator } from "@/components/ui/separator"
import { Textarea } from "@/components/ui/textarea"
import type { UserRole } from "@/lib/types"
import { useAuthStore } from "@/store/auth"
export default function VerifyPage() {
const [submitted, setSubmitted] = useState(false)
const [verifyRole, setVerifyRole] = useState<UserRole | "">("")
const verificationStatus = useAuthStore((state) => state.verificationStatus)
const submitVerification = useAuthStore((state) => state.submitVerification)
const submitted = Object.values(verificationStatus).includes("pending")
if (submitted) {
return (
@@ -68,7 +73,7 @@ export default function VerifyPage() {
<CardContent className="space-y-6">
<div className="space-y-2">
<Label></Label>
<Select>
<Select value={verifyRole} onValueChange={(value) => setVerifyRole(value as UserRole)}>
<SelectTrigger>
<SelectValue placeholder="选择认证类型" />
</SelectTrigger>
@@ -115,7 +120,14 @@ export default function VerifyPage() {
<p className="text-xs text-muted-foreground"> JPGPNG 5MB</p>
</div>
<Button className="w-full" onClick={() => setSubmitted(true)}>
<Button
className="w-full"
disabled={!verifyRole}
onClick={() => {
if (!verifyRole) return
submitVerification(verifyRole)
}}
>
</Button>
</CardContent>
+19 -1
View File
@@ -1,8 +1,16 @@
"use client"
import Link from "next/link"
import { AuthGuard } from "@/components/auth-guard"
import { DashboardSidebar } from "@/components/dashboard-sidebar"
import { Header } from "@/components/header"
import { Button } from "@/components/ui/button"
import { useAuthStore } from "@/store/auth"
export default function DashboardLayout({ children }: { children: React.ReactNode }) {
const isAuthenticated = useAuthStore((state) => state.isAuthenticated)
const currentRole = useAuthStore((state) => state.currentRole)
return (
<div className="flex min-h-screen flex-col">
<Header />
@@ -11,7 +19,17 @@ export default function DashboardLayout({ children }: { children: React.ReactNod
<DashboardSidebar />
</div>
<main className="flex-1 p-6">
<AuthGuard>{children}</AuthGuard>
<AuthGuard>
{isAuthenticated && currentRole === "consumer" ? (
<div className="flex min-h-[50vh] items-center justify-center">
<Button asChild>
<Link href="/"></Link>
</Button>
</div>
) : (
children
)}
</AuthGuard>
</main>
</div>
</div>