import { AuthenticationError, PromiseReturnType } from "blitz" import Link from "next/link" import { LabeledTextField } from "app/core/components/LabeledTextField" import { Form, FORM_ERROR } from "app/core/components/Form" import login from "app/auth/mutations/login" import { Login } from "app/auth/validations" import { useMutation } from "@blitzjs/rpc" import { Routes } from "@blitzjs/next" type LoginFormProps = { onSuccess?: (user: PromiseReturnType) => void } export const LoginForm = (props: LoginFormProps) => { const [loginMutation] = useMutation(login) return (

Login

{ try { const user = await loginMutation(values) props.onSuccess?.(user) } catch (error: any) { if (error instanceof AuthenticationError) { return { [FORM_ERROR]: "Sorry, those credentials are invalid" } } else { return { [FORM_ERROR]: "Sorry, we had an unexpected error. Please try again. - " + error.toString(), } } } }} >
Or{" "} Sign Up
) } export default LoginForm