From c8eebb2de4bf2acff728f2880baf955419d8571f Mon Sep 17 00:00:00 2001 From: g-but <41178744+g-but@users.noreply.github.com> Date: Mon, 25 May 2026 18:53:09 +0200 Subject: [PATCH] fix(it-hilfe): show sign-in CTA when anonymous submitter has existing account MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Silent UX gap in the just-shipped anonymous-post flow. Three submitter states needed three success branches but only two existed: newAccount=true → "check your email" claim screen ✓ status=unauth, newAccount=false → (missing) silently redirected to the request page, where the still- logged-out browser tab couldn't accept offers or take owner actions, with no hint that the user has an account or what to do status=auth (logged-in submitter) → normal redirect to request ✓ Real submitter behaviour: someone uses anonymous-post with an email that already has an account (forgot they had one, switched browsers, old subscription, etc.). Backend correctly attaches the request to that account (62ba111c suppresses the duplicate email for them). But the frontend was treating them like a logged-in user on the success path — redirect to /it-hilfe/, no sign-in prompt. Fix: 1. useCreateITHilfeForm now tracks `existingAccountAttached` alongside `anonymousAccountCreated`. Flips when result.data.newAccount is false AND `status === 'unauthenticated'`. Also tracks `submittedRequestId` so the page can build a callbackUrl. 2. /it-hilfe/create gains a third success branch: "We attached your request to your existing account under . Sign in to see and manage offers." Primary CTA is a sign-in button with `?callbackUrl=/it-hilfe/` so the user lands on their own request after authenticating — same one-tap-to-request seam we closed for the new-account path via the claim email's callbackUrl (aedf208b). End state: every combination of (auth, account-existed-or-not) leaves the user with a clear next action and a working link to their request. tsc + lint clean on touched files. 458 IT-Hilfe tests across 33 suites pass (no new tests for this — the change is purely UI-state branching, hook has no test suite, and the route response shape is unchanged so existing route tests still cover the API contract). Co-Authored-By: Claude Opus 4.7 (1M context) --- src/app/[locale]/it-hilfe/create/page.tsx | 27 +++++++++++++++++++++++ src/hooks/useCreateITHilfeForm.ts | 22 +++++++++++++++--- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/app/[locale]/it-hilfe/create/page.tsx b/src/app/[locale]/it-hilfe/create/page.tsx index bedfb14d5..485b8c243 100644 --- a/src/app/[locale]/it-hilfe/create/page.tsx +++ b/src/app/[locale]/it-hilfe/create/page.tsx @@ -47,6 +47,8 @@ export default function CreatePeerRepairPage() { error, success, anonymousAccountCreated, + existingAccountAttached, + submittedRequestId, formData, aiFieldMeta, updateField, @@ -88,6 +90,31 @@ export default function CreatePeerRepairPage() { ) } + if (success && existingAccountAttached) { + const loginHref = submittedRequestId + ? `/auth/login?callbackUrl=${encodeURIComponent(`/it-hilfe/${submittedRequestId}`)}` + : '/auth/login' + return ( + + + + Anfrage gespeichert! + +

+ Wir haben deine Anfrage an dein bestehendes Konto unter{' '} + {formData.submitterEmail} angehängt. + Melde dich an, um Angebote zu sehen und deine Anfrage zu verwalten. +

+ +

+ Passwort vergessen? Du kannst es auf der Anmeldeseite zurücksetzen. +

+
+ ) + } + if (success) { return (
diff --git a/src/hooks/useCreateITHilfeForm.ts b/src/hooks/useCreateITHilfeForm.ts index dbfa5e2e6..90d1cc9c0 100644 --- a/src/hooks/useCreateITHilfeForm.ts +++ b/src/hooks/useCreateITHilfeForm.ts @@ -35,6 +35,13 @@ export function useCreateITHilfeForm(errorCreateFailed: string, errorGeneric: st // check their email instead of redirecting (they can't view the request // until they set a password via the claim link). const [anonymousAccountCreated, setAnonymousAccountCreated] = useState(false) + // `existingAccountAttached` flips when a logged-out submitter's email + // matched an existing account. The request was attached silently; we + // can't auto-redirect to the request page because the browser tab is + // still logged-out, so owner actions wouldn't work — show a "sign in + // to manage" CTA instead. + const [existingAccountAttached, setExistingAccountAttached] = useState(false) + const [submittedRequestId, setSubmittedRequestId] = useState(null) const [formData, setFormData] = useState(INITIAL_IT_HILFE_FORM) const [aiFieldMeta, setAiFieldMeta] = useState>({}) @@ -151,11 +158,18 @@ export function useCreateITHilfeForm(errorCreateFailed: string, errorGeneric: st } setSuccess(true) - // newAccount → backend just provisioned an account; user must claim - // via email link before they can view the request. Skip the redirect - // and let the page render the check-your-email state. + setSubmittedRequestId(result.data.requestId) + // Three branches based on auth state + whether the backend created + // a new account: + // + // newAccount=true → "check your email" claim flow + // status=unauth, newAccount=false → "we attached this to your + // existing account, sign in" + // status=authenticated (or default) → normal redirect to request if (result.data.newAccount) { setAnonymousAccountCreated(true) + } else if (status === 'unauthenticated') { + setExistingAccountAttached(true) } else { setTimeout(() => { router.push(`/it-hilfe/${result.data!.requestId}`) @@ -176,6 +190,8 @@ export function useCreateITHilfeForm(errorCreateFailed: string, errorGeneric: st error, success, anonymousAccountCreated, + existingAccountAttached, + submittedRequestId, formData, aiFieldMeta, updateField,