Merge pull request 'feat: register page' (#91)
Some checks failed
docker-build / docker (push) Waiting to run
container-scan / Container Scan (push) Has been cancelled

Reviewed-on: #91
Reviewed-by: Dominik <mail@dominikstahl.dev>
This commit is contained in:
Dominik 2025-06-11 06:13:23 +00:00
commit 15fbf27459
3 changed files with 81 additions and 18 deletions

View file

@ -104,7 +104,7 @@ This project is built with a modern tech stack:
yarn prisma:generate
```
```bash
yarn prisa:db:push
yarn prisma:db:push
```
- Run the following command to apply migrations and generate Prisma Client:
```bash

View file

@ -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 (
<div className='grid grid-cols-1 gap-1'>
@ -24,6 +26,7 @@ export default function LabeledInput({
defaultValue={value}
id={name}
name={name}
autoComplete={autocomplete}
/>
</div>
);

View file

@ -1,19 +1,30 @@
'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 { useRef, useState } from 'react';
const SIGNIN_ERROR_URL = '/error';
export default function LoginForm() {
const [isSignUp, setIsSignUp] = useState(false);
const formRef = useRef<HTMLFormElement>(null);
return (
<form
ref={formRef}
className='flex flex-col gap-5 w-full'
action={async (formData) => {
'use server';
'use client';
try {
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,6 +33,46 @@ export default function LoginForm() {
}
}}
>
{isSignUp ? (
<>
<LabeledInput
type='text'
label='First Name'
placeholder='Your first name'
name='firstName'
autocomplete='given-name'
/>
<LabeledInput
type='text'
label='Last Name'
placeholder='Your last name'
name='lastName'
autocomplete='family-name'
/>
<LabeledInput
type='email'
label='E-Mail'
placeholder='Your email address'
name='email'
autocomplete='email'
/>
<LabeledInput
type='password'
label='Password'
placeholder='Create a password'
name='password'
autocomplete='new-password'
/>
<LabeledInput
type='password'
label='Confirm Password'
placeholder='Repeat your password'
name='confirmPassword'
autocomplete='new-password'
/>
</>
) : (
<>
<LabeledInput
type='email'
label='E-Mail or Username'
@ -34,12 +85,21 @@ export default function LoginForm() {
placeholder="Let's hope you remember it"
name='password'
/>
</>
)}
<div className='grid grid-rows-2 gap-2'>
<Button type='submit' variant='primary'>
Login
{isSignUp ? 'Sign Up' : 'Login'}
</Button>
<Button type='submit' variant='outline_primary'>
Sign Up
<Button
type='button'
variant='outline_primary'
onClick={() => {
formRef.current?.reset();
setIsSignUp((v) => !v);
}}
>
{isSignUp ? 'Back to Login' : 'Sign Up'}
</Button>
</div>
</form>