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>
38 lines
972 B
TypeScript
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('/');
|
|
}
|