feat(auth): hook up verification code sending
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { IconInput } from "@/components/ui/icon-input"
|
||||
import { Label } from "@/components/ui/label"
|
||||
import { resetPassword } from "@/lib/api"
|
||||
import { resetPassword, sendForgotPasswordCode } from "@/lib/api"
|
||||
import { toApiError } from "@/lib/errors"
|
||||
import { notifyInfo, notifySuccess } from "@/lib/toast"
|
||||
import { standardSchemaResolver } from "@hookform/resolvers/standard-schema"
|
||||
@@ -33,6 +33,7 @@ export default function ForgotPasswordPage() {
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
getValues,
|
||||
trigger,
|
||||
formState: { errors, isSubmitting },
|
||||
} = useForm({
|
||||
@@ -49,9 +50,14 @@ export default function ForgotPasswordPage() {
|
||||
const isValid = await trigger("email")
|
||||
if (!isValid) return
|
||||
|
||||
// Mock sending code
|
||||
setCountdown(60)
|
||||
notifySuccess("验证码已发送到你的邮箱")
|
||||
try {
|
||||
const email = getValues("email")
|
||||
await sendForgotPasswordCode(email)
|
||||
setCountdown(60)
|
||||
notifySuccess("验证码已发送到你的邮箱")
|
||||
} catch (err) {
|
||||
notifyInfo(toApiError(err).msg)
|
||||
}
|
||||
}
|
||||
|
||||
const onSubmit = async (data: z.infer<typeof forgotSchema>) => {
|
||||
|
||||
Reference in New Issue
Block a user