From 22398a502b15b1e94f8845e1124dfd1007c45d58 Mon Sep 17 00:00:00 2001 From: Amruth Pillai Date: Sat, 4 Jul 2026 21:47:11 +0200 Subject: [PATCH] =?UTF-8?q?refactor(web):=20finding=204=20=E2=80=94=20extr?= =?UTF-8?q?act=20runSignIn=20helper=20in=20SocialAuthButtons?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three near-identical toast→auth→error→invalidate handlers collapsed into one generic runSignIn(fn) function. Claude-Session: https://claude.ai/code/session_012Bnvt1MghwHj4qQRxuQUGa --- .../features/auth/components/social-auth.tsx | 71 ++++--------------- 1 file changed, 15 insertions(+), 56 deletions(-) diff --git a/apps/web/src/features/auth/components/social-auth.tsx b/apps/web/src/features/auth/components/social-auth.tsx index 1f4b3f52a..f8a71cf42 100644 --- a/apps/web/src/features/auth/components/social-auth.tsx +++ b/apps/web/src/features/auth/components/social-auth.tsx @@ -66,68 +66,20 @@ type SocialAuthButtonsProps = { function SocialAuthButtons({ providers, requestSignUp }: SocialAuthButtonsProps) { const router = useRouter(); - const handleSocialLogin = async (provider: string) => { + const runSignIn = async (fn: () => Promise<{ error: { message?: string } | null }>) => { const toastId = toast.loading(t`Signing in...`); - - const { error } = await authClient.signIn.social(getSocialSignInOptions(provider, requestSignUp)); - + const { error } = await fn(); if (error) { toast.error( error.message || t({ - comment: "Fallback toast when social sign-in fails without a provider error message", + comment: "Fallback toast when sign-in fails without an error message", message: "Failed to sign in. Please try again.", }), { id: toastId }, ); return; } - - toast.dismiss(toastId); - await router.invalidate(); - }; - - const handleOAuthLogin = async () => { - const toastId = toast.loading(t`Signing in...`); - - const { error } = await authClient.signIn.oauth2({ - providerId: "custom", - callbackURL: "/dashboard", - }); - - if (error) { - toast.error( - error.message || - t({ - comment: "Fallback toast when custom OAuth sign-in fails without a provider error message", - message: "Failed to sign in. Please try again.", - }), - { id: toastId }, - ); - return; - } - - toast.dismiss(toastId); - await router.invalidate(); - }; - - const handlePasskeyLogin = async () => { - const toastId = toast.loading(t`Signing in...`); - - const { error } = await authClient.signIn.passkey({ autoFill: false }); - - if (error) { - toast.error( - error.message || - t({ - comment: "Fallback toast when passkey sign-in fails without an error message", - message: "Failed to sign in. Please try again.", - }), - { id: toastId }, - ); - return; - } - toast.dismiss(toastId); await router.invalidate(); }; @@ -136,7 +88,14 @@ function SocialAuthButtons({ providers, requestSignUp }: SocialAuthButtonsProps)