'use client'; //=========================================== // THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY UNLESS YOU ALSO EDIT THE CORRESPONDING FILE IN packages/template //=========================================== import { yupResolver } from "@hookform/resolvers/yup"; import { passwordSchema, strictEmailSchema, yupObject } from "@hexclave/shared/dist/schema-fields"; import { runAsynchronouslyWithAlert } from "@hexclave/shared/dist/utils/promises"; import { Button, Input, Label, PasswordInput } from "@hexclave/ui"; import { useState } from "react"; import { useForm } from "react-hook-form"; import * as yup from "yup"; import { useStackApp } from ".."; import { useTranslation } from "../lib/translations"; import { FormWarningText } from "./elements/form-warning"; import { StyledLink } from "./link"; export function CredentialSignIn() { const { t } = useTranslation(); const schema = yupObject({ email: strictEmailSchema(t('Please enter a valid email')).defined().nonEmpty(t('Please enter your email')), password: passwordSchema.defined().nonEmpty(t('Please enter your password')) }); const { register, handleSubmit, setError, formState: { errors } } = useForm({ resolver: yupResolver(schema) }); const app = useStackApp(); const [loading, setLoading] = useState(false); const onSubmit = async (data: yup.InferType) => { setLoading(true); try { const { email, password } = data; const result = await app.signInWithCredential({ email, password, }); if (result.status === 'error') { setError('email', { type: 'manual', message: result.error.message }); } } finally { setLoading(false); } }; return (
runAsynchronouslyWithAlert(handleSubmit(onSubmit)(e))} noValidate > { e.preventDefault(); runAsynchronouslyWithAlert(app.redirectToForgotPassword()); }} > {t('Forgot password?')} ); }