feat(auth): add signup page with form action

Composes BrandPanel + SignupForm in responsive split layout.
Server action POSTs to /v1/auth/signup and redirects to
/household/setup on success.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-02 14:47:36 +02:00
parent d3a8518298
commit 596652d6e4
3 changed files with 122 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
import { redirect, fail } from '@sveltejs/kit';
import { apiClient } from '$lib/server/api';
import type { Actions } from './$types';
export const actions = {
default: async ({ request, fetch }) => {
const formData = await request.formData();
const displayName = formData.get('displayName') as string;
const email = formData.get('email') as string;
const password = formData.get('password') as string;
const api = apiClient(fetch);
const { data, error } = await api.POST('/v1/auth/signup', {
body: { displayName, email, password }
});
if (error) {
return fail(400, { error: 'Registrierung fehlgeschlagen. Bitte versuche es erneut.' });
}
redirect(303, '/household/setup');
}
} satisfies Actions;

View File

@@ -0,0 +1,14 @@
<script lang="ts">
import BrandPanel from '$lib/auth/BrandPanel.svelte';
import SignupForm from '$lib/auth/SignupForm.svelte';
</script>
<!-- Mobile: stacked, Desktop: side by side -->
<div class="flex min-h-screen flex-col md:flex-row">
<BrandPanel />
<div class="flex flex-1 flex-col justify-center px-[20px] py-[24px] md:px-[56px] md:py-[48px]">
<div class="max-w-[380px]">
<SignupForm />
</div>
</div>
</div>

View File

@@ -0,0 +1,85 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
vi.mock('$env/dynamic/private', () => ({
env: { BACKEND_URL: 'http://localhost:8080' }
}));
const mockPost = vi.fn();
vi.mock('$lib/server/api', () => ({
apiClient: () => ({ POST: mockPost })
}));
describe('signup form action', () => {
let actions: any;
beforeEach(async () => {
mockPost.mockReset();
const mod = await import('./+page.server');
actions = mod.actions;
});
function createRequest(formData: Record<string, string>) {
const fd = new FormData();
for (const [key, value] of Object.entries(formData)) {
fd.append(key, value);
}
return {
request: { formData: () => Promise.resolve(fd) },
fetch: vi.fn(),
cookies: { get: vi.fn(), set: vi.fn() }
} as any;
}
it('calls POST /v1/auth/signup with form data', async () => {
mockPost.mockResolvedValue({ data: { data: { id: '123' } }, error: undefined });
try {
await actions.default(createRequest({
displayName: 'Sarah',
email: 'sarah@example.com',
password: 'password123'
}));
} catch {
// redirect throws
}
expect(mockPost).toHaveBeenCalledWith('/v1/auth/signup', {
body: {
displayName: 'Sarah',
email: 'sarah@example.com',
password: 'password123'
}
});
});
it('redirects to /household/setup on success', async () => {
mockPost.mockResolvedValue({ data: { data: { id: '123' } }, error: undefined });
try {
await actions.default(createRequest({
displayName: 'Sarah',
email: 'sarah@example.com',
password: 'password123'
}));
expect.unreachable();
} catch (e: any) {
expect(e.status).toBe(303);
expect(e.location).toBe('/household/setup');
}
});
it('returns fail with error message on API error', async () => {
mockPost.mockResolvedValue({
data: undefined,
error: { status: 409, message: 'Email already registered' }
});
const result = await actions.default(createRequest({
displayName: 'Sarah',
email: 'sarah@example.com',
password: 'password123'
}));
expect(result.status).toBe(400);
});
});