From 782133dbc73149b3e7872719f6957e3f8a2acc14 Mon Sep 17 00:00:00 2001 From: Max Peintner Date: Tue, 30 Jun 2026 15:35:10 +0200 Subject: [PATCH] fix(login): improve error handling for user registration (#12338) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Which Problems Are Solved When the registerUser server action failed during registration, all errors from addHumanUser, createSessionWithRetry, and getUserByID propagated as uncaught exceptions to the client component's generic catch block, which always showed the same "Could not register user" message. This made it impossible to distinguish between user creation failures, session creation failures, and user lookup failures — both for end users and in server logs. # How the Problems Are Solved Added .catch() handlers on the three gRPC calls in registerUser that log the actual error and return null, allowing the existing null-check guard clauses to return step-specific error messages (couldNotCreateUser, couldNotCreateSession, userNotFound) through handleServerActionResponse. This gives users more specific feedback and provides server-side logging to narrow down the root cause of flaky signup failures. --- apps/login/src/lib/server/register.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/apps/login/src/lib/server/register.ts b/apps/login/src/lib/server/register.ts index ce085c8f4..9b927c0a9 100644 --- a/apps/login/src/lib/server/register.ts +++ b/apps/login/src/lib/server/register.ts @@ -87,6 +87,9 @@ export async function registerUser( lastName: command.lastName, password: command.password ? command.password : undefined, organization: command.organization, + }).catch((error) => { + logger.error("Failed to create user", { error }); + return null; }); if (!addResponse) { @@ -110,8 +113,12 @@ export async function registerUser( checks, requestId: command.requestId, lifetime: command.password ? loginSettings?.passwordCheckLifetime : undefined, + }).catch((error) => { + logger.error("Failed to create session after user creation", { error }); + return null; }); - const session = result.session; + + const session = result?.session; if (!session || !session.factors?.user) { return { error: t("errors.couldNotCreateSession") }; @@ -144,9 +151,12 @@ export async function registerUser( return { redirect: "/passkey/set?" + params }; } else { - const userResponse = await getUserByID({ serviceConfig, userId: session?.factors?.user?.id }); + const userResponse = await getUserByID({ serviceConfig, userId: session?.factors?.user?.id }).catch((error) => { + logger.error("Failed to get user after session creation", { error }); + return null; + }); - if (!userResponse.user) { + if (!userResponse?.user) { return { error: t("errors.userNotFound") }; }