diff --git a/app/auth/sign-in/page.tsx b/app/auth/sign-in/page.tsx index b7c0682..d93a6ad 100644 --- a/app/auth/sign-in/page.tsx +++ b/app/auth/sign-in/page.tsx @@ -5,28 +5,80 @@ import { authClient } from "@/lib/auth-client"; import { useRouter } from "next/navigation"; import Link from "next/link"; +const socialProviders = [ + { + id: "google", + name: "Google", + subtitle: "Platzhalter", + icon: "G", + }, + { + id: "apple", + name: "Apple", + subtitle: "Platzhalter", + icon: "", + }, +]; + export default function SignInPage() { const router = useRouter(); - const [email, setEmail] = useState(""); + const [identifier, setIdentifier] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [magicLinkMessage, setMagicLinkMessage] = useState(""); + const [socialMessage, setSocialMessage] = useState(""); const [loading, setLoading] = useState(false); const [magicLinkLoading, setMagicLinkLoading] = useState(false); + const toGermanAuthError = (message?: string) => { + if (!message) { + return "Anmeldung fehlgeschlagen. Bitte versuche es erneut."; + } + + const normalized = message.toLowerCase(); + + if (normalized.includes("invalid") || normalized.includes("credentials")) { + return "E-Mail/Username oder Passwort ist nicht korrekt."; + } + + if (normalized.includes("verify") || normalized.includes("verification")) { + return "Bitte bestätige zuerst deine E-Mail-Adresse."; + } + + if (normalized.includes("username")) { + return "Username oder Passwort ist nicht korrekt."; + } + + return "Anmeldung fehlgeschlagen. Bitte prüfe deine Eingaben."; + }; + const handleSignIn = async (e: React.FormEvent) => { e.preventDefault(); setError(""); + setMagicLinkMessage(""); setLoading(true); try { - const result = await authClient.signIn.email({ - email, - password, - }); + const trimmedIdentifier = identifier.trim(); + const isEmailInput = trimmedIdentifier.includes("@"); + + if (!trimmedIdentifier) { + setError("Bitte gib deine E-Mail-Adresse oder deinen Username ein."); + return; + } + + const result = isEmailInput + ? await authClient.signIn.email({ + email: trimmedIdentifier, + password, + }) + : await authClient.signIn.username({ + username: trimmedIdentifier, + password, + }); if (result.error) { - setError(result.error.message ?? "Anmeldung fehlgeschlagen"); + setError(toGermanAuthError(result.error.message)); } else { router.push("/dashboard"); } @@ -41,21 +93,28 @@ export default function SignInPage() { setError(""); setMagicLinkMessage(""); - if (!email) { - setError("Bitte gib deine E-Mail-Adresse ein"); + const trimmedIdentifier = identifier.trim(); + + if (!trimmedIdentifier) { + setError("Bitte gib zuerst deine E-Mail-Adresse ein."); + return; + } + + if (!trimmedIdentifier.includes("@")) { + setError("Magic Link funktioniert nur mit einer E-Mail-Adresse."); return; } setMagicLinkLoading(true); try { const result = await authClient.signIn.magicLink({ - email, + email: trimmedIdentifier, callbackURL: "/dashboard", errorCallbackURL: "/auth/sign-in", }); if (result.error) { - setError(result.error.message ?? "Magic Link konnte nicht gesendet werden"); + setError(toGermanAuthError(result.error.message)); } else { setMagicLinkMessage("Magic Link gesendet. Prüfe dein Postfach."); } @@ -66,6 +125,12 @@ export default function SignInPage() { } }; + const handleSocialPlaceholder = (provider: string) => { + setError(""); + setMagicLinkMessage(""); + setSocialMessage(`${provider}-Login ist aktuell als Platzhalter eingebunden.`); + }; + return (