This commit is contained in:
cirroskais 2024-04-01 00:55:54 -04:00
parent c35a0bf12a
commit fd9b6d1588
No known key found for this signature in database
GPG key ID: 5FC73EBF2678E33D
6 changed files with 75 additions and 16 deletions

9
docker-compose.dev.yml Normal file
View file

@ -0,0 +1,9 @@
services:
db:
image: mariadb
restart: always
environment:
MARIADB_DATABASE: file-uploader
MARIADB_ROOT_PASSWORD: development
ports:
- '3306:3306'

View file

@ -1,6 +1,13 @@
import { redirect } from '@sveltejs/kit'; import { redirect } from '@sveltejs/kit';
const PUBLIC_RESOURCES = ['/', '/api', '/terms', '/privacy']; const PUBLIC_RESOURCES = [
'/',
'/api',
'/api/auth/register',
'/api/auth/login',
'/terms',
'/privacy'
];
/** @type {import('@sveltejs/kit').Handle} */ /** @type {import('@sveltejs/kit').Handle} */
export async function handle({ event, resolve }) { export async function handle({ event, resolve }) {

View file

@ -1,7 +1,7 @@
<script> <script>
import { CircleAlert, Check } from 'lucide-svelte'; import { CircleAlert, Check } from 'lucide-svelte';
export let type, name, id, placeholder, bind, required; export let type, name, id, placeholder, value, required;
</script> </script>
<!-- insane that i have to do this because --> <!-- insane that i have to do this because -->
@ -20,7 +20,7 @@
{id} {id}
{placeholder} {placeholder}
{required} {required}
bind:value={bind} bind:value
/> />
<div class="peer-invalid:flex hidden my-auto"> <div class="peer-invalid:flex hidden my-auto">
<CircleAlert /> <CircleAlert />
@ -43,7 +43,7 @@
{id} {id}
{placeholder} {placeholder}
{required} {required}
bind:value={bind} bind:value
/> />
<div class="peer-invalid:flex hidden my-auto"> <div class="peer-invalid:flex hidden my-auto">
<CircleAlert /> <CircleAlert />
@ -66,7 +66,7 @@
{id} {id}
{placeholder} {placeholder}
{required} {required}
bind:value={bind} bind:value
/> />
<div class="peer-invalid:flex hidden my-auto"> <div class="peer-invalid:flex hidden my-auto">
<CircleAlert /> <CircleAlert />

View file

@ -1,6 +1,6 @@
<script> <script>
import { blur } from 'svelte/transition'; import { blur } from 'svelte/transition';
import { Mail, SquareAsterisk, Undo, User, UserPlus, Dot } from 'lucide-svelte'; import { Mail, SquareAsterisk, Undo, User, UserPlus } from 'lucide-svelte';
import { toast } from 'svelte-sonner'; import { toast } from 'svelte-sonner';
import Logo from '$lib/components/Logo.svelte'; import Logo from '$lib/components/Logo.svelte';
@ -17,10 +17,43 @@
async function register() { async function register() {
disabled = true; disabled = true;
setTimeout(() => { const id = toast.loading('Registering...');
toast('Failed to register.');
disabled = false; if (!username) {
}, 5_000); toast.error('Missing username.', { id });
return (disabled = false);
}
if (!email) {
toast.error('Missing email.', { id });
return (disabled = false);
}
if (!password || !cpassword) {
toast.error('Missing password.', { id });
return (disabled = false);
}
if (password !== cpassword) {
toast.error('Your passwords do not match.', { id });
return (disabled = false);
}
const response = await fetch('/api/auth/register', {
method: 'POST',
body: JSON.stringify({ username, email, password })
}).catch((_) => toast.error(_.message));
const body = await response.json().catch((_) => toast.error(_.message));
if (response.status >= 400 && response.status < 500) {
toast.error(body?.error || 'Client Error', { id });
return (disabled = false);
}
if (response.status >= 500) {
toast.error(body?.error || 'Server Error', { id });
return (disabled = false);
}
} }
</script> </script>
@ -36,7 +69,7 @@
name={'username'} name={'username'}
id={'username'} id={'username'}
placeholder={'Username'} placeholder={'Username'}
bind={username} bind:value={username}
required={true} required={true}
> >
<User /> <User />
@ -46,7 +79,7 @@
name={'email'} name={'email'}
id={'email'} id={'email'}
placeholder={'user@example.com'} placeholder={'user@example.com'}
bind={email} bind:value={email}
required={true} required={true}
> >
<Mail /> <Mail />
@ -56,7 +89,7 @@
name={'password'} name={'password'}
id={'password'} id={'password'}
placeholder={'•'.repeat(16)} placeholder={'•'.repeat(16)}
bind={password} bind:value={password}
required={true} required={true}
> >
<SquareAsterisk /> <SquareAsterisk />
@ -66,7 +99,7 @@
name={'cpassword'} name={'cpassword'}
id={'cpassword'} id={'cpassword'}
placeholder={'•'.repeat(16)} placeholder={'•'.repeat(16)}
bind={cpassword} bind:value={cpassword}
required={true} required={true}
> >
<SquareAsterisk /> <SquareAsterisk />

View file

@ -4,6 +4,7 @@
import { writable } from 'svelte/store'; import { writable } from 'svelte/store';
import { page } from '$app/stores'; import { page } from '$app/stores';
import { browser } from '$app/environment'; import { browser } from '$app/environment';
import { goto } from '$app/navigation';
import ThemeSwitcher from '$lib/components/ThemeSwitcher.svelte'; import ThemeSwitcher from '$lib/components/ThemeSwitcher.svelte';
import Button from '$lib/components/Button.svelte'; import Button from '$lib/components/Button.svelte';
@ -19,8 +20,9 @@
} }
state.subscribe((value) => { state.subscribe((value) => {
if (!browser) return; if (browser) {
window.history.replaceState(null, '', '#' + value); goto('#' + value);
}
}); });
</script> </script>

View file

@ -4,4 +4,12 @@ import { json } from '@sveltejs/kit';
export async function POST(event) { export async function POST(event) {
const { request, cookies, locals } = event; const { request, cookies, locals } = event;
const body = await request.json(); const body = await request.json();
if (!body?.username || body?.username.length > 16 || body?.username.length < 3)
return json({ error: 'Invalid username' }, { status: 400 });
if (!body?.password || body?.password.length > 128 || body?.password.length < 6)
return json({ error: 'Invalid password' }, { status: 400 });
return json({ error: 'Not Implemented' }, { status: 500 });
} }