BUG FIX && 权限验证

This commit is contained in:
SpecialX
2026-01-09 14:10:04 +08:00
parent 15d9ea9cb8
commit 15fcf2bc78
7 changed files with 114 additions and 9 deletions

View File

@@ -2,24 +2,44 @@
import * as React from "react"
import Link from "next/link"
import { useRouter } from "next/navigation"
import { toast } from "sonner"
import { Button } from "@/shared/components/ui/button"
import { Input } from "@/shared/components/ui/input"
import { Label } from "@/shared/components/ui/label"
import { cn } from "@/shared/lib/utils"
import { Loader2, Github } from "lucide-react"
import type { ActionState } from "@/shared/types/action-state"
type RegisterFormProps = React.HTMLAttributes<HTMLDivElement>
type RegisterFormProps = React.HTMLAttributes<HTMLDivElement> & {
registerAction: (formData: FormData) => Promise<ActionState>
}
export function RegisterForm({ className, ...props }: RegisterFormProps) {
export function RegisterForm({ className, registerAction, ...props }: RegisterFormProps) {
const [isLoading, setIsLoading] = React.useState<boolean>(false)
const router = useRouter()
async function onSubmit(event: React.SyntheticEvent) {
event.preventDefault()
setIsLoading(true)
setTimeout(() => {
try {
const form = event.currentTarget as HTMLFormElement
const formData = new FormData(form)
const res = await registerAction(formData)
if (res.success) {
toast.success(res.message || "Account created")
router.push("/login")
router.refresh()
} else {
toast.error(res.message || "Failed to create account")
}
} catch {
toast.error("Failed to create account")
} finally {
setIsLoading(false)
}, 3000)
}
}
return (
@@ -38,6 +58,7 @@ export function RegisterForm({ className, ...props }: RegisterFormProps) {
<Label htmlFor="name">Full Name</Label>
<Input
id="name"
name="name"
placeholder="John Doe"
type="text"
autoCapitalize="words"
@@ -50,6 +71,7 @@ export function RegisterForm({ className, ...props }: RegisterFormProps) {
<Label htmlFor="email">Email</Label>
<Input
id="email"
name="email"
placeholder="name@example.com"
type="email"
autoCapitalize="none"
@@ -62,6 +84,7 @@ export function RegisterForm({ className, ...props }: RegisterFormProps) {
<Label htmlFor="password">Password</Label>
<Input
id="password"
name="password"
type="password"
autoComplete="new-password"
disabled={isLoading}