Files
logbuch/app/login/actions.ts
Reinhard X. Fürst 4e53a7a5cd Initial implementation: Logbuch Sternwarte Welzheim
Vollständige Next.js 16 Webanwendung als Logbuch für die Sternwarte Welzheim.
4 Kuppeln (West/Ost/Süd/Pluto), BEO-basierte Authentifizierung mit erzwungenem
Passwort-Wechsel beim Erstlogin, MySQL-Backend, Docker-Deployment.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-27 17:11:27 +02:00

38 lines
972 B
TypeScript

'use server';
import { redirect } from 'next/navigation';
import { verifyCredentials } from '@/lib/auth';
import { createSession } from '@/lib/session';
export async function login(
_prevState: { error: string } | undefined,
formData: FormData
): Promise<{ error: string }> {
const kuerzel = (formData.get('username') as string)?.trim();
const password = formData.get('password') as string;
if (!kuerzel || !password) {
return { error: 'Bitte Kürzel und Passwort eingeben.' };
}
const result = await verifyCredentials(kuerzel, password);
if (!result || !result.valid) {
return { error: 'Ungültiges Kürzel oder Passwort.' };
}
await createSession({
kuerzel: result.beo.Kuerzel,
beoId: result.beo.ID,
beoName: result.beo.Name,
mustChangePassword: result.beo.MustChangePassword === 1,
isAuthenticated: true,
});
if (result.beo.MustChangePassword === 1) {
redirect('/change-password');
}
redirect('/');
}