Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Refactor EmailSignIn component: streamline account existence check and remove unused code

Kiran K62f85c20b2a1
diff --git a/apps/web/ui/auth/login/email-sign-in.tsx b/apps/web/ui/auth/login/email-sign-in.tsx
index c798fc10b7..62ae9130e3 100644
--- a/apps/web/ui/auth/login/email-sign-in.tsx
+++ b/apps/web/ui/auth/login/email-sign-in.tsx
@@ -16,10 +16,8 @@ export const EmailSignIn = ({ redirectTo }: { redirectTo?: string }) => {
const searchParams = useSearchParams();
const next = searchParams?.get("next");
const { isMobile } = useMediaQuery();
-
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
- const [checkingEmailPassword, setCheckingEmailPassword] = useState(false);
const {
showPasswordField,
@@ -33,9 +31,6 @@ export const EmailSignIn = ({ redirectTo }: { redirectTo?: string }) => {
} = useContext(LoginFormContext);
const { executeAsync, isPending } = useAction(checkAccountExistsAction, {
- onSuccess: (data) => {
- console.log(data);
- },
onError: ({ error }) => {
toast.error(error.serverError);
},
@@ -61,6 +56,12 @@ export const EmailSignIn = ({ redirectTo }: { redirectTo?: string }) => {
setShowPasswordField(true);
return;
}
+
+ if (!accountExists) {
+ setClickedMethod(undefined);
+ toast.error("No account found with that email address.");
+ return;
+ }
}
setClickedMethod("email");
@@ -79,7 +80,7 @@ export const EmailSignIn = ({ redirectTo }: { redirectTo?: string }) => {
return;
}
- const provider = hasPassword && password ? "credentials" : "email";
+ const provider = password && hasPassword ? "credentials" : "email";
const response = await signIn(provider, {
email,
@@ -115,64 +116,6 @@ export const EmailSignIn = ({ redirectTo }: { redirectTo?: string }) => {
if (provider === "credentials") {
router.push(response?.url || redirectTo || "/workspaces");
}
-
- // fetch("/api/auth/account-exists", {
- // method: "POST",
- // headers: { "Content-Type": "application/json" },
- // body: JSON.stringify({ email }),
- // }).then(async (res) => {
- // if (!res.ok) {
- // const error = await res.text();
- // toast.error(error);
- // setClickedMethod(undefined);
- // return;
- // }
-
- // const { accountExists, hasPassword } = await res.json();
-
- // if (!accountExists) {
- // setClickedMethod(undefined);
- // toast.error("No account found with that email address.");
- // return;
- // }
-
- // const provider = hasPassword && password ? "credentials" : "email";
-
- // const response = await signIn(provider, {
- // email,
- // redirect: false,
- // callbackUrl: next || redirectTo || "/workspaces",
- // ...(password && { password }),
- // });
-
- // if (!response) {
- // return;
- // }
-
- // if (!response.ok && response.error) {
- // if (errorCodes[response.error]) {
- // toast.error(errorCodes[response.error]);
- // } else {
- // toast.error(response.error);
- // }
-
- // setClickedMethod(undefined);
- // return;
- // }
-
- // setLastUsedAuthMethod("email");
-
- // if (provider === "email") {
- // toast.success("Email sent - check your inbox!");
- // setEmail("");
- // setClickedMethod(undefined);
- // return;
- // }
-
- // if (provider === "credentials") {
- // router.push(response?.url || redirectTo || "/workspaces");
- // }
- // });
}}
className="flex flex-col gap-y-3"
>
@@ -227,7 +170,7 @@ export const EmailSignIn = ({ redirectTo }: { redirectTo?: string }) => {
setAuthMethod("email");
},
})}
- loading={checkingEmailPassword || clickedMethod === "email"}
+ loading={clickedMethod === "email" || isPending}
disabled={clickedMethod && clickedMethod !== "email"}
/>
</form>