From a6de744f91a2d253d70f723a7e9d6a447e5e9333 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sat, 8 Mar 2025 12:37:50 -0600 Subject: [PATCH] fix(2fa): improve error handling and display for two-factor authentication setup - Handle potential errors when enabling two-factor authentication - Provide more detailed error messages for password verification - Update client-side error handling to display specific error messages - Add base URL configuration for non-cloud environments --- .../components/dashboard/settings/profile/enable-2fa.tsx | 6 +++--- packages/server/src/lib/auth.ts | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/dokploy/components/dashboard/settings/profile/enable-2fa.tsx b/apps/dokploy/components/dashboard/settings/profile/enable-2fa.tsx index f47c8d9c..ccfa0a1e 100644 --- a/apps/dokploy/components/dashboard/settings/profile/enable-2fa.tsx +++ b/apps/dokploy/components/dashboard/settings/profile/enable-2fa.tsx @@ -64,12 +64,12 @@ export const Enable2FA = () => { const handlePasswordSubmit = async (formData: PasswordForm) => { setIsPasswordLoading(true); try { - const { data: enableData } = await authClient.twoFactor.enable({ + const { data: enableData, error } = await authClient.twoFactor.enable({ password: formData.password, }); if (!enableData) { - throw new Error("No data received from server"); + throw new Error(error?.message || "Unknown error"); } if (enableData.backupCodes) { @@ -95,7 +95,7 @@ export const Enable2FA = () => { error instanceof Error ? error.message : "Error setting up 2FA", ); passwordForm.setError("password", { - message: "Error verifying password", + message: `Error verifying password: ${error instanceof Error ? error.message : "Unknown error"}`, }); } finally { setIsPasswordLoading(false); diff --git a/packages/server/src/lib/auth.ts b/packages/server/src/lib/auth.ts index 1efa1730..3c0f39d3 100644 --- a/packages/server/src/lib/auth.ts +++ b/packages/server/src/lib/auth.ts @@ -14,6 +14,9 @@ const { handler, api } = betterAuth({ provider: "pg", schema: schema, }), + ...(!IS_CLOUD && { + baseURL: "http://localhost:3000", + }), logger: { disabled: process.env.NODE_ENV === "production", },