feat: add auth guards to protected routes and extend requireAuth coverage
This commit is contained in:
+13
-1
@@ -1,10 +1,22 @@
|
||||
"use client"
|
||||
|
||||
import { usePathname } from "next/navigation"
|
||||
import { AuthGuard } from "@/components/auth-guard"
|
||||
import { Header } from "@/components/header"
|
||||
|
||||
export default function OrderLayout({ children }: { children: React.ReactNode }) {
|
||||
const pathname = usePathname()
|
||||
const protectedPathPrefixes = ["/orders", "/order", "/chat", "/dispute", "/review"]
|
||||
const shouldGuard = protectedPathPrefixes.some(
|
||||
(prefix) => pathname === prefix || pathname.startsWith(`${prefix}/`),
|
||||
)
|
||||
|
||||
return (
|
||||
<div className="flex min-h-screen flex-col">
|
||||
<Header />
|
||||
<main className="flex-1 bg-muted/30">{children}</main>
|
||||
<main className="flex-1 bg-muted/30">
|
||||
{shouldGuard ? <AuthGuard>{children}</AuthGuard> : children}
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -12,9 +12,11 @@ import { Label } from "@/components/ui/label"
|
||||
import { Separator } from "@/components/ui/separator"
|
||||
import { Textarea } from "@/components/ui/textarea"
|
||||
import { mockPlayers, mockServices, walletBalance } from "@/lib/mock-data"
|
||||
import { useRequireAuth } from "@/lib/use-require-auth"
|
||||
|
||||
export default function NewOrderPage() {
|
||||
const searchParams = useSearchParams()
|
||||
const { requireAuth } = useRequireAuth()
|
||||
const serviceId = searchParams.get("serviceId")
|
||||
|
||||
const service = mockServices.find((s) => s.id === serviceId)
|
||||
@@ -168,7 +170,7 @@ export default function NewOrderPage() {
|
||||
className="w-full"
|
||||
size="lg"
|
||||
disabled={walletBalance < totalPrice}
|
||||
onClick={() => setSubmitted(true)}
|
||||
onClick={() => requireAuth(() => setSubmitted(true))}
|
||||
>
|
||||
确认支付 ¥{totalPrice}
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user