- 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.
48 lines
1.6 KiB
JavaScript
48 lines
1.6 KiB
JavaScript
// 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);
|