fix: sync verification state with auth guards
This commit is contained in:
@@ -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">支持 JPG、PNG 格式,单张不超过 5MB</p>
|
||||
</div>
|
||||
|
||||
<Button className="w-full" onClick={() => setSubmitted(true)}>
|
||||
<Button
|
||||
className="w-full"
|
||||
disabled={!verifyRole}
|
||||
onClick={() => {
|
||||
if (!verifyRole) return
|
||||
submitVerification(verifyRole)
|
||||
}}
|
||||
>
|
||||
提交认证申请
|
||||
</Button>
|
||||
</CardContent>
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user