From d37aa88ab7010e61363d7e041e88fb7a2a00924c Mon Sep 17 00:00:00 2001 From: Micha Date: Sun, 8 Jun 2025 00:53:27 +0200 Subject: [PATCH] feat: enhance login form with sign-up input-fields and autocomplete attributes --- src/components/labeled-input.tsx | 3 + src/components/user/login-form.tsx | 88 ++++++++++++++++++++++++------ 2 files changed, 74 insertions(+), 17 deletions(-) diff --git a/src/components/labeled-input.tsx b/src/components/labeled-input.tsx index 250dd5f..94563dc 100644 --- a/src/components/labeled-input.tsx +++ b/src/components/labeled-input.tsx @@ -7,12 +7,14 @@ export default function LabeledInput({ placeholder, value, name, + autocomplete, }: { type: 'text' | 'email' | 'password'; label: string; placeholder?: string; value?: string; name?: string; + autocomplete?: string; }) { return (
@@ -24,6 +26,7 @@ export default function LabeledInput({ defaultValue={value} id={name} name={name} + autoComplete={autocomplete} />
); diff --git a/src/components/user/login-form.tsx b/src/components/user/login-form.tsx index a8e6382..2ed61e4 100644 --- a/src/components/user/login-form.tsx +++ b/src/components/user/login-form.tsx @@ -1,19 +1,27 @@ +'use client'; import { signIn } from '@/auth'; import LabeledInput from '@/components/labeled-input'; import { Button } from '@/components/custom-ui/button'; import { AuthError } from 'next-auth'; import { redirect } from 'next/navigation'; +import { useState } from 'react'; const SIGNIN_ERROR_URL = '/error'; export default function LoginForm() { + const [isSignUp, setIsSignUp] = useState(false); + return (
{ - 'use server'; + 'use client'; try { - await signIn('credentials', formData); + if (isSignUp) { + // handle sign up logic here + } else { + await signIn('credentials', formData); + } } catch (error) { if (error instanceof AuthError) { return redirect(`${SIGNIN_ERROR_URL}?error=${error.type}`); @@ -22,24 +30,70 @@ export default function LoginForm() { } }} > - - + {isSignUp ? ( + <> + + + + + + + ) : ( + <> + + + + )}
-