added axios client

This commit is contained in:
Milo Schwartz
2024-10-06 12:39:05 -04:00
parent 3c69acaab7
commit 29777da430
7 changed files with 81 additions and 41 deletions

View File

@@ -24,6 +24,8 @@ import {
} from "@/components/ui/card";
import { Alert, AlertDescription } from "@/components/ui/alert";
import { ExclamationTriangleIcon } from "@radix-ui/react-icons";
import api from "@app/api";
import { LoginBody, LoginResponse } from "@server/routers/auth";
const formSchema = z.object({
email: z.string().email({ message: "Invalid email address" }),
@@ -43,9 +45,19 @@ export default function LoginForm() {
},
});
function onSubmit(values: z.infer<typeof formSchema>) {
console.log(values);
setError("Invalid email or password. Please try again.");
async function onSubmit(values: z.infer<typeof formSchema>) {
const { email, password } = values;
const res = await api
.post<LoginBody, LoginResponse>("/auth/login", {
email,
password,
})
.catch((e) => {
setError(
e.response?.data?.message ||
"An error occurred while logging in",
);
});
}
return (