added signup and verify email forms

This commit is contained in:
Milo Schwartz 2024-10-12 23:00:36 -04:00
parent 41cbde1474
commit f3eb76fd5e
No known key found for this signature in database
14 changed files with 882 additions and 11 deletions

View file

@ -22,10 +22,10 @@ import {
CardTitle,
} from "@/components/ui/card";
import { Alert, AlertDescription } from "@/components/ui/alert";
import { ExclamationTriangleIcon } from "@radix-ui/react-icons";
import { LoginResponse } from "@server/routers/auth";
import { api } from "@app/api";
import { useRouter } from "next/navigation";
import { AxiosResponse } from "axios";
type LoginFormProps = {
redirect?: string;
@ -54,7 +54,7 @@ export default function LoginForm({ redirect }: LoginFormProps) {
async function onSubmit(values: z.infer<typeof formSchema>) {
const { email, password } = values;
const res = await api
.post<LoginResponse>("/auth/login", {
.post<AxiosResponse<LoginResponse>>("/auth/login", {
email,
password,
})
@ -68,6 +68,14 @@ export default function LoginForm({ redirect }: LoginFormProps) {
if (res && res.status === 200) {
setError(null);
console.log(res)
if (res.data?.data?.emailVerificationRequired) {
router.push("/auth/verify-email");
return;
}
if (redirect && typeof redirect === "string") {
window.location.href = redirect;
} else {
@ -79,7 +87,7 @@ export default function LoginForm({ redirect }: LoginFormProps) {
return (
<Card className="w-full max-w-md mx-auto">
<CardHeader>
<CardTitle>Secure Login</CardTitle>
<CardTitle>Login</CardTitle>
<CardDescription>
Enter your credentials to access your dashboard
</CardDescription>
@ -124,8 +132,7 @@ export default function LoginForm({ redirect }: LoginFormProps) {
)}
/>
{error && (
<Alert variant="destructive">
<ExclamationTriangleIcon className="h-4 w-4" />
<Alert>
<AlertDescription>{error}</AlertDescription>
</Alert>
)}