import type { BlitzPage } from "blitz"; import { useRouter, Routes, AuthenticationError, Link, useMutation } from "blitz"; import BaseLayout from "../../core/layouts/base-layout"; import { AuthForm as Form, FORM_ERROR } from "../components/auth-form"; import { Login } from "../validations"; import { LabeledTextField } from "../components/labeled-text-field"; import login from "../mutations/login"; const SignIn: BlitzPage = () => { const router = useRouter(); const [loginMutation] = useMutation(login); return (
Need an account?  Create yours for free ), submit: "Sign in", }} schema={Login} initialValues={{ email: "", password: "" }} onSubmit={async (values) => { try { await loginMutation(values); const next = router.query.next ? decodeURIComponent(router.query.next as string) : Routes.Messages(); router.push(next); } 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(), }; } } }} > ); }; SignIn.redirectAuthenticatedTo = Routes.Messages(); SignIn.getLayout = (page) => {page}; export default SignIn;