fix(web): handle real signup errors on register (no more false success)
better-auth's signUp.email returns { error } instead of throwing (same as
login.tsx), so the old try/catch never caught auth failures: a failed signup
still showed "Hesap oluşturuldu!", fired user_signed_up / CompleteRegistration,
and redirected to the dashboard. Now we check the returned error, distinguish
"e-posta zaten kayıtlı" (via /users/check-email) from other failures (showing
the actual reason, e.g. weak password), keep the user on the form, and only
fire success analytics on real success. Network failures get a distinct
"Bağlantı hatası" toast.
Also: CTA "Kayıt Ol" -> "Ücretsiz Başla" (matches pricing) and added
"Spam göndermeyiz" trust microcopy.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { api } from "@/lib/api-client";
|
||||
import { signIn, signUp } from "@/lib/auth-client";
|
||||
import { startAction } from "@/lib/faro";
|
||||
import { track as trackMeta } from "@/lib/meta-pixel";
|
||||
@@ -40,16 +41,40 @@ function RegisterPage() {
|
||||
setLoading(true);
|
||||
|
||||
try {
|
||||
await signUp.email({ name, email, password, callbackURL: redirectUrl });
|
||||
capture("user_signed_up", { method: "email" });
|
||||
trackMeta("CompleteRegistration", { method: "email" });
|
||||
// better-auth returns { error } rather than throwing (see login.tsx).
|
||||
// The old code awaited without checking error, so failed signups still
|
||||
// reported success, fired user_signed_up, and redirected to the dashboard.
|
||||
const { error } = await signUp.email({ name, email, password, callbackURL: redirectUrl });
|
||||
|
||||
if (error) {
|
||||
let exists = false;
|
||||
try {
|
||||
({ exists } = await api.post<{ exists: boolean }>("/users/check-email", { email }));
|
||||
} catch {
|
||||
// fall through to a generic message
|
||||
}
|
||||
if (exists) {
|
||||
toast.error("Bu e-posta zaten kayıtlı", {
|
||||
description: "Bunun yerine giriş yapmayı deneyin.",
|
||||
});
|
||||
} else {
|
||||
toast.error("Kayıt başarısız", {
|
||||
description:
|
||||
error.message ?? "Şifre en az 8 karakter, 1 büyük harf ve 1 rakam içermelidir.",
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// The referral code travels via `?ref=` in redirectUrl; the welcome
|
||||
// onboarding modal on the search page is the single place that applies it
|
||||
// (covers both email and Google OAuth signups).
|
||||
capture("user_signed_up", { method: "email" });
|
||||
trackMeta("CompleteRegistration", { method: "email" });
|
||||
toast.success("Hesap oluşturuldu!");
|
||||
window.location.href = redirectUrl;
|
||||
} catch {
|
||||
toast.error("Kayıt başarısız. Bu e-posta zaten kullanılıyor olabilir.");
|
||||
toast.error("Bağlantı hatası", { description: "Lütfen tekrar deneyin." });
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -163,12 +188,12 @@ function RegisterPage() {
|
||||
/>
|
||||
</div>
|
||||
<Button type="submit" className="w-full" disabled={loading}>
|
||||
{loading ? "Kayıt yapılıyor..." : "Kayıt Ol"}
|
||||
{loading ? "Kayıt yapılıyor..." : "Ücretsiz Başla"}
|
||||
</Button>
|
||||
</form>
|
||||
|
||||
<p className="text-center text-xs text-muted-foreground">
|
||||
Kayıt olunca hemen VIN aramaya başlayın
|
||||
Kayıt olunca hemen VIN aramaya başlarsın · Spam göndermeyiz
|
||||
</p>
|
||||
|
||||
<p className="text-center text-sm">
|
||||
|
||||
Reference in New Issue
Block a user