import { useState, useEffect } from "react"; import { toast } from "sonner"; import { authClient } from "../../lib/auth-client"; type Tab = "login" | "register"; type AuthModalProps = { onClose: () => void; onSuccess: () => void }; type LoginFormProps = { onSuccess: () => void }; const LoginForm = ({ onSuccess }: LoginFormProps) => { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [isPending, setIsPending] = useState(false); const handleSubmit = async () => { setIsPending(true); await authClient.signIn.email( { email, password }, { onSuccess: () => { toast.success("Welcome back!"); onSuccess(); }, onError: (ctx) => { toast.error(ctx.error.message ?? "Something went wrong."); setIsPending(false); }, }, ); }; return (
); }; type RegisterFormProps = { onSuccess: () => void }; const RegisterForm = ({ onSuccess }: RegisterFormProps) => { const [name, setName] = useState(""); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [isPending, setIsPending] = useState(false); const handleSubmit = async () => { setIsPending(true); await authClient.signUp.email( { name, email, password }, { onSuccess: () => { toast.success("Check your email to verify your account."); onSuccess(); }, onError: (ctx) => { toast.error(ctx.error.message ?? "Something went wrong."); setIsPending(false); }, }, ); }; return ( ); }; type SocialButtonsProps = { onSuccess: () => void }; const SocialButtons = ({ onSuccess }: SocialButtonsProps) => { const handleSocial = (provider: "google" | "github") => { void authClient.signIn.social( { provider, callbackURL: window.location.origin }, { onSuccess, onError: (ctx) => { toast.error(ctx.error.message ?? "Something went wrong."); }, }, ); }; return (