restructure: flatten workspace nesting, move devcontainer to root
- backend/workspaces/backend/ → backend/ - backend/workspaces/frontend/ → frontend/ - backend/.devcontainer/ + .vscode/ → repo root (where VS Code expects them) - loose scripts/SQL files → scripts/ - replace nested git repo with single repo at project root - update docker-compose.yml build context and devcontainer.json path - add root .gitignore Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
53
frontend/src/routes/login/+page.server.ts
Normal file
53
frontend/src/routes/login/+page.server.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { fail, redirect, type Actions } from '@sveltejs/kit';
|
||||
|
||||
export const actions = {
|
||||
login: async ({ request, cookies, fetch }) => {
|
||||
const data = await request.formData();
|
||||
const username = data.get('username') as string;
|
||||
const password = data.get('password') as string;
|
||||
|
||||
if (!username || !password) {
|
||||
return fail(400, { error: 'Bitte Benutzername und Passwort eingeben.' });
|
||||
}
|
||||
|
||||
// Wir bauen den Basic Auth Header
|
||||
const credentials = btoa(`${username}:${password}`);
|
||||
const authHeader = `Basic ${credentials}`;
|
||||
|
||||
try {
|
||||
// Test-Request an das Backend (z.B. an den Upload-Endpunkt oder einen speziellen /me Endpunkt)
|
||||
// Wir nutzen hier http://localhost:8080, da beide Container im selben Netz sind (oder localhost im DevContainer)
|
||||
const response = await fetch('http://localhost:8080/api/users/me', {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Authorization': authHeader
|
||||
}
|
||||
});
|
||||
|
||||
if (response.status === 401 || response.status === 403) {
|
||||
return fail(401, { error: 'Ungültige Zugangsdaten.' });
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
return fail(500, { error: 'Serverfehler beim Login.' });
|
||||
}
|
||||
|
||||
// Login erfolgreich! Wir speichern den Header in einem Cookie.
|
||||
// (In Produktion würde man hier ein Session-Token nutzen, aber für Basic Auth müssen wir es mitschleifen)
|
||||
cookies.set('auth_token', authHeader, {
|
||||
path: '/',
|
||||
httpOnly: true, // JavaScript kann das Cookie nicht lesen (Schutz vor XSS)
|
||||
sameSite: 'strict',
|
||||
secure: false, // Auf true setzen, wenn wir HTTPS haben
|
||||
maxAge: 60 * 60 * 24 // 1 Tag
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return fail(500, { error: 'Verbindung zum Backend fehlgeschlagen.' });
|
||||
}
|
||||
|
||||
// Weiterleitung zur Startseite
|
||||
return redirect(303, '/');
|
||||
}
|
||||
} satisfies Actions;
|
||||
Reference in New Issue
Block a user