V1.1.0: Auth dazugefügt

This commit is contained in:
2026-02-28 15:56:33 +00:00
parent fec587a524
commit c067a42302
9 changed files with 376 additions and 3 deletions

33
app/login/actions.ts Normal file
View File

@@ -0,0 +1,33 @@
'use server';
import { verifyCredentials } from '@/lib/auth';
import { createSession, deleteSession } from '@/lib/session';
import { redirect } from 'next/navigation';
export async function login(prevState: any, formData: FormData) {
const username = formData.get('username') as string;
const password = formData.get('password') as string;
console.log('Login attempt:', { username, passwordLength: password?.length });
console.log('AUTH_USERS env:', process.env.AUTH_USERS);
if (!username || !password) {
return { error: 'Bitte Benutzername und Passwort eingeben' };
}
const isValid = verifyCredentials(username, password);
console.log('Credentials valid:', isValid);
if (!isValid) {
return { error: 'Ungültige Anmeldedaten' };
}
await createSession(username);
redirect('/');
}
export async function logout() {
await deleteSession();
redirect('/login');
}