Mist, jetzt vielleicht

This commit is contained in:
rxf
2026-03-11 20:33:19 +01:00
parent bc235e4e32
commit a949ebcdc8
28 changed files with 1666 additions and 74 deletions

36
lib/auth.ts Normal file
View File

@@ -0,0 +1,36 @@
/**
* Authentifizierungsbibliothek
* Benutzer via Umgebungsvariable konfigurieren:
* AUTH_USERS=user1:passwort1,user2:passwort2
*/
export interface User {
username: string;
password: string;
}
export function getUsers(): User[] {
const usersString = process.env.AUTH_USERS || '';
if (!usersString) {
console.warn('AUTH_USERS nicht in .env konfiguriert');
return [];
}
return usersString
.split(',')
.map((userPair) => {
const [username, password] = userPair.trim().split(':');
return { username: username?.trim(), password: password?.trim() };
})
.filter((user) => user.username && user.password);
}
export function verifyCredentials(username: string, password: string): boolean {
const users = getUsers();
const user = users.find(u => u.username === username);
if (!user) return false;
return user.password === password;
}
export function isAuthEnabled(): boolean {
return !!process.env.AUTH_USERS;
}