V 1.0.1: Auth erfolgreich
This commit is contained in:
@@ -8,17 +8,12 @@ export async function login(prevState: any, formData: FormData) {
|
|||||||
const username = formData.get('username') as string;
|
const username = formData.get('username') as string;
|
||||||
const password = formData.get('password') 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) {
|
if (!username || !password) {
|
||||||
return { error: 'Bitte Benutzername und Passwort eingeben' };
|
return { error: 'Bitte Benutzername und Passwort eingeben' };
|
||||||
}
|
}
|
||||||
|
|
||||||
const isValid = verifyCredentials(username, password);
|
const isValid = verifyCredentials(username, password);
|
||||||
|
|
||||||
console.log('Credentials valid:', isValid);
|
|
||||||
|
|
||||||
if (!isValid) {
|
if (!isValid) {
|
||||||
return { error: 'Ungültige Anmeldedaten' };
|
return { error: 'Ungültige Anmeldedaten' };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
const bcrypt = require('bcryptjs');
|
|
||||||
|
|
||||||
// Direkt aus .env kopiert
|
|
||||||
const AUTH_USERS = 'rxf:$2b$10$VdshbfnSFZIn59QJqDRiROi.ekU83ObiQBM.R3MVaSIcGQb5eYbEq';
|
|
||||||
|
|
||||||
console.log('=== AUTH DEBUG ===\n');
|
|
||||||
console.log('AUTH_USERS:', AUTH_USERS);
|
|
||||||
console.log('');
|
|
||||||
|
|
||||||
const usersString = AUTH_USERS || '';
|
|
||||||
const users = usersString
|
|
||||||
.split(',')
|
|
||||||
.map((userPair) => {
|
|
||||||
const [username, passwordHash] = userPair.trim().split(':');
|
|
||||||
return { username: username?.trim(), passwordHash: passwordHash?.trim() };
|
|
||||||
})
|
|
||||||
.filter((user) => user.username && user.passwordHash);
|
|
||||||
|
|
||||||
console.log('Parsed users:', JSON.stringify(users, null, 2));
|
|
||||||
console.log('');
|
|
||||||
|
|
||||||
// Test credentials
|
|
||||||
const testUser = 'rxf';
|
|
||||||
const testPassword = 'Fluorit';
|
|
||||||
|
|
||||||
const user = users.find(u => u.username === testUser);
|
|
||||||
console.log('Found user:', user);
|
|
||||||
console.log('');
|
|
||||||
|
|
||||||
if (user) {
|
|
||||||
console.log('Testing password:', testPassword);
|
|
||||||
console.log('Against hash:', user.passwordHash);
|
|
||||||
const result = bcrypt.compareSync(testPassword, user.passwordHash);
|
|
||||||
console.log('Result:', result);
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import { NextRequest, NextResponse } from 'next/server';
|
import { NextRequest, NextResponse } from 'next/server';
|
||||||
import { cookies } from 'next/headers';
|
|
||||||
import { jwtVerify } from 'jose';
|
import { jwtVerify } from 'jose';
|
||||||
|
|
||||||
const SESSION_COOKIE_NAME = 'auth_session';
|
const SESSION_COOKIE_NAME = 'auth_session';
|
||||||
@@ -28,8 +27,7 @@ export async function middleware(request: NextRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check for session cookie
|
// Check for session cookie
|
||||||
const cookieStore = await cookies();
|
const sessionCookie = request.cookies.get(SESSION_COOKIE_NAME);
|
||||||
const sessionCookie = cookieStore.get(SESSION_COOKIE_NAME);
|
|
||||||
|
|
||||||
if (!sessionCookie) {
|
if (!sessionCookie) {
|
||||||
return NextResponse.redirect(new URL('/login', request.url));
|
return NextResponse.redirect(new URL('/login', request.url));
|
||||||
|
|||||||
Reference in New Issue
Block a user