import { zodResolver } from "@hookform/resolvers/zod" import { createFileRoute, Link as RouterLink, redirect, } from "@tanstack/react-router" import { useForm } from "react-hook-form" import { z } from "zod" import type { Body_login_login_access_token as AccessToken } from "@/client" import { AuthLayout } from "@/components/Common/AuthLayout" import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form" import { Input } from "@/components/ui/input" import { LoadingButton } from "@/components/ui/loading-button" import { PasswordInput } from "@/components/ui/password-input" import useAuth, { isLoggedIn } from "@/hooks/useAuth" const formSchema = z.object({ username: z.email(), password: z .string() .min(1, { message: "Password is required" }) .min(8, { message: "Password must be at least 8 characters" }), }) satisfies z.ZodType type FormData = z.infer export const Route = createFileRoute("/login")({ component: Login, beforeLoad: async () => { if (isLoggedIn()) { throw redirect({ to: "/", }) } }, head: () => ({ meta: [ { title: "Log In - FastAPI Template", }, ], }), }) function Login() { const { loginMutation } = useAuth() const form = useForm({ resolver: zodResolver(formSchema), mode: "onBlur", criteriaMode: "all", defaultValues: { username: "", password: "", }, }) const onSubmit = (data: FormData) => { if (loginMutation.isPending) return loginMutation.mutate(data) } return (

Login to your account

( Email )} /> (
Password Forgot your password?
)} /> Log In
Don't have an account yet?{" "} Sign up
) }