Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion client-next/src/app/api/[...path]/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ async function handler(request, { params }) {
const [name, value] = nameValue.split('=')

// Extract cookie attributes
const options = {}
const options = {
path: '/',
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
sameSite: 'lax',
}

cookieParts.slice(1).forEach(part => {
const lower = part.toLowerCase()
if (lower === 'httponly') options.httpOnly = true
Expand All @@ -88,10 +94,13 @@ async function handler(request, { params }) {
options.path = part.split('=')[1]
} else if (lower.startsWith('max-age=')) {
options.maxAge = parseInt(part.split('=')[1])
} else if (lower.startsWith('domain=')) {
// Skip domain from backend, let browser use current domain
}
})

// Set cookie on response using NextResponse.cookies API
// Domain is automatically set to the current request domain (postscholar.org)
response.cookies.set(name, value, options)
console.log('[API Proxy] Set cookie:', name, 'with options:', options)
}
Expand Down
21 changes: 21 additions & 0 deletions server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,27 @@ if (!isTest) {
requireEnv('DATABASE_URL')
requireEnv('JWT_SECRET')
requireEnv('CLIENT_URL')

// Validate OAuth provider configs (warn if incomplete)
const hasGoogle = process.env.GOOGLE_CLIENT_ID && process.env.GOOGLE_CLIENT_SECRET
const hasGithub = process.env.GITHUB_CLIENT_ID && process.env.GITHUB_CLIENT_SECRET
const hasOrcid = process.env.ORCID_CLIENT_ID && process.env.ORCID_CLIENT_SECRET

if (!hasGoogle && !hasGithub && !hasOrcid) {
console.warn('⚠️ No OAuth providers configured. Social sign-in will not work.')
}
if (process.env.GOOGLE_CLIENT_ID && !process.env.GOOGLE_CLIENT_SECRET) {
console.error('❌ GOOGLE_CLIENT_ID set but GOOGLE_CLIENT_SECRET missing')
process.exit(1)
}
if (process.env.GITHUB_CLIENT_ID && !process.env.GITHUB_CLIENT_SECRET) {
console.error('❌ GITHUB_CLIENT_ID set but GITHUB_CLIENT_SECRET missing')
process.exit(1)
}
if (process.env.ORCID_CLIENT_ID && !process.env.ORCID_CLIENT_SECRET) {
console.error('❌ ORCID_CLIENT_ID set but ORCID_CLIENT_SECRET missing')
process.exit(1)
}
}

module.exports = {
Expand Down
14 changes: 14 additions & 0 deletions server/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ if (process.env.NODE_ENV === 'production') {
// neon() returns an array of rows directly
const rows = await sql(text, params || [])
return { rows }
},

// Transaction wrapper for Neon serverless (no persistent client)
// Executes callback with a transaction-like interface
connect: async () => {
const sql = neon(process.env.DATABASE_URL)

return {
query: async (text, params) => {
const rows = await sql(text, params || [])
return { rows }
},
release: () => {},
}
}
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const authLimiter = rateLimit({
legacyHeaders: false,
message: { error: 'Too many attempts, please try again later.' },
keyGenerator: rateLimiterKeyGenerator,
skip: () => config.isProd, // Disable in production (Workers) for now
skip: () => config.isProd, // TODO: Replace with Cloudflare Rate Limiting API or Durable Objects
})

const generalLimiter = rateLimit({
Expand All @@ -52,7 +52,7 @@ const generalLimiter = rateLimit({
legacyHeaders: false,
message: { error: 'Too many requests, please try again later.' },
keyGenerator: rateLimiterKeyGenerator,
skip: () => config.isProd, // Disable in production (Workers) for now
skip: () => config.isProd, // TODO: Replace with Cloudflare Rate Limiting API or Durable Objects
})

const db = require('./db')
Expand Down
11 changes: 0 additions & 11 deletions wrangler.jsonc

This file was deleted.

Loading