diff --git a/.gitignore b/.gitignore index 24ab70c..16712c6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,42 +1,52 @@ +``` # Dependencies -node_modules -.pnp -.pnp.js +node_modules/ -# Testing -coverage -*.log +# Environment +.env +.env.local +.env.* + +# Editor +.vscode/ +.idea/ -# Next.js -.next/ -out/ -build -dist +# Logs +*.log -# Production -.vercel -.env*.local +# Python +__pycache__/ +*.pyc +*.pyo +*.pyd -# Environment files -.env -.env.production +# Build outputs +dist/ +build/ +*.js +*.ts -# Debug -npm-debug.log* -yarn-debug.log* -yarn-error.log* +# Temp files +*.tmp +*.swp +*.swo # OS .DS_Store Thumbs.db -# IDE -.vscode/ -.idea/ -*.swp -*.swo -*~ +# Coverage +coverage/ +htmlcov/ +.coverage + +# Cache +.mypy_cache/ +.pytest_cache/ +.nyc_output/ +coverage/ -# Misc -.turbo -.cache +# System +.DS_Store +Thumbs.db +``` \ No newline at end of file diff --git a/src/lib/api.ts b/src/lib/api.ts index fcb3e77..0fd5f88 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -25,6 +25,26 @@ export class ApiError extends Error { } } +/** + * Get authentication token for API requests + * This function attempts to get the token from the NextAuth session + */ +async function getAuthToken(): Promise { + // In client-side, we can use the getSession function + if (typeof window !== 'undefined') { + try { + // For client-side, we'll rely on NextAuth's automatic cookie handling + return null; // NextAuth handles authentication via cookies automatically + } catch (error) { + console.error('Error getting auth token:', error); + return null; + } + } + + // In server-side, we might need to extract token differently + return null; +} + /** * Base fetch function with error handling */ @@ -33,12 +53,25 @@ async function fetchApi( options: RequestInit = {} ): Promise> { try { + // For client-side requests, relative URLs work fine + // For server-side requests in Next.js, the fetch is handled internally + + // Get auth token if available + const token = await getAuthToken(); + + const headers: HeadersInit = { + 'Content-Type': 'application/json', + ...options.headers, + }; + + // Add authorization header if token is available + if (token) { + headers['Authorization'] = `Bearer ${token}`; + } + const response = await fetch(url, { ...options, - headers: { - 'Content-Type': 'application/json', - ...options.headers, - }, + headers, }); const data = await response.json(); diff --git a/src/lib/authOptions.ts b/src/lib/authOptions.ts index bbdffc5..752af65 100644 --- a/src/lib/authOptions.ts +++ b/src/lib/authOptions.ts @@ -94,4 +94,7 @@ export const authOptions: NextAuthOptions = { error: '/auth/error', }, debug: process.env.NODE_ENV === 'development', + // Ensure proper domain configuration for production + secret: process.env.NEXTAUTH_SECRET, + trustHost: true, }; diff --git a/src/lib/db.ts b/src/lib/db.ts index bbd6268..1a41695 100644 --- a/src/lib/db.ts +++ b/src/lib/db.ts @@ -31,9 +31,11 @@ if (!process.env.DATABASE_URL) { // Create a connection pool const pool = new Pool({ connectionString: process.env.DATABASE_URL, - max: 20, - idleTimeoutMillis: 30000, - connectionTimeoutMillis: 2000, + max: process.env.NODE_ENV === 'production' ? 20 : 10, // Higher pool size in production + min: process.env.NODE_ENV === 'production' ? 5 : 2, // Higher min in production + idleTimeoutMillis: process.env.NODE_ENV === 'production' ? 30000 : 10000, + connectionTimeoutMillis: 5000, // Increase timeout to 5 seconds + maxUses: process.env.NODE_ENV === 'production' ? 100 : 50, // Recycle connections after this many uses }); // Test the connection on startup