325c07b469
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
28 lines
753 B
TypeScript
28 lines
753 B
TypeScript
'use server';
|
|
|
|
import { verifyCredentials } from '@/lib/auth';
|
|
import { createSession, deleteSession } from '@/lib/session';
|
|
import { redirect } from 'next/navigation';
|
|
|
|
export async function login(prevState: { error: string } | null | undefined, formData: FormData) {
|
|
const username = formData.get('username') as string;
|
|
const password = formData.get('password') as string;
|
|
|
|
if (!username || !password) {
|
|
return { error: 'Bitte Benutzername und Passwort eingeben' };
|
|
}
|
|
|
|
const isValid = await verifyCredentials(username, password);
|
|
if (!isValid) {
|
|
return { error: 'Ungültige Anmeldedaten' };
|
|
}
|
|
|
|
await createSession(username);
|
|
redirect('/');
|
|
}
|
|
|
|
export async function logout() {
|
|
await deleteSession();
|
|
redirect('/login');
|
|
}
|