feat: upgrade next-auth to v5.0.0-beta.29 and refactor authentication middleware

- Updated next-auth dependency in package.json to version 5.0.0-beta.29.
- Refactored create-admin script to use a valid email format.
- Implemented authentication middleware for various API routes to enforce access control.
- Refactored API route handlers to improve readability and maintainability.
- Enhanced error handling in authentication error page.
- Added detailed tests for authentication flow, including protected routes and NextAuth endpoints.
This commit is contained in:
2025-06-25 12:32:13 +02:00
parent 035a0386d7
commit c1bb4c44fd
24 changed files with 626 additions and 369 deletions

47
test-nextauth.mjs Normal file
View File

@@ -0,0 +1,47 @@
// Simple test for NextAuth endpoints
const BASE_URL = 'http://localhost:3000';
async function testNextAuthEndpoints() {
console.log('🔐 Testing NextAuth Endpoints\n');
// Test session endpoint
try {
const sessionResponse = await fetch(`${BASE_URL}/api/auth/session`);
console.log(`Session endpoint: ${sessionResponse.status} ${sessionResponse.statusText}`);
if (sessionResponse.ok) {
const sessionData = await sessionResponse.json();
console.log(`Session data: ${JSON.stringify(sessionData)}\n`);
}
} catch (error) {
console.log(`Session endpoint error: ${error.message}\n`);
}
// Test providers endpoint
try {
const providersResponse = await fetch(`${BASE_URL}/api/auth/providers`);
console.log(`Providers endpoint: ${providersResponse.status} ${providersResponse.statusText}`);
if (providersResponse.ok) {
const providersData = await providersResponse.json();
console.log(`Providers: ${JSON.stringify(providersData, null, 2)}\n`);
}
} catch (error) {
console.log(`Providers endpoint error: ${error.message}\n`);
}
// Test CSRF endpoint
try {
const csrfResponse = await fetch(`${BASE_URL}/api/auth/csrf`);
console.log(`CSRF endpoint: ${csrfResponse.status} ${csrfResponse.statusText}`);
if (csrfResponse.ok) {
const csrfData = await csrfResponse.json();
console.log(`CSRF token present: ${csrfData.csrfToken ? 'Yes' : 'No'}\n`);
}
} catch (error) {
console.log(`CSRF endpoint error: ${error.message}\n`);
}
}
testNextAuthEndpoints().catch(console.error);