fix(security): drop wildcard CORS + redundant OPTIONS from 24 API routes (P0 #5 PARTIAL → RESOLVED) #19
25 changed files with 29 additions and 261 deletions
29
.github/workflows/ci.yml
vendored
29
.github/workflows/ci.yml
vendored
|
|
@ -113,6 +113,35 @@ jobs:
|
||||||
fi
|
fi
|
||||||
echo "OK: no forbidden dev endpoints under pages/api/."
|
echo "OK: no forbidden dev endpoints under pages/api/."
|
||||||
|
|
||||||
|
forbidden-cors-headers:
|
||||||
|
name: No wildcard CORS in pages/api
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Fail if any pages/api/ handler carries Access-Control-Allow-Origin
|
||||||
|
run: |
|
||||||
|
# The tcg-vault frontend and API are served from the same Vercel
|
||||||
|
# deployment (same origin), so CORS headers serve no purpose and
|
||||||
|
# are a documented attack surface (see .convoys/cors-tighten.md
|
||||||
|
# and AGENTS.md Gotcha #5). Brief 4 of fix-auth-bypass cleaned
|
||||||
|
# login.js + register.js; the cors-tighten convoy swept the
|
||||||
|
# remaining 24 files. This job locks the cleanup in.
|
||||||
|
#
|
||||||
|
# If a future cross-origin caller is legitimately needed, design
|
||||||
|
# a proper CORS layer (probably via middleware) rather than
|
||||||
|
# scaffolding wildcards into individual handlers.
|
||||||
|
MATCHES=$(grep -rEn 'Access-Control-Allow-(Origin|Methods|Headers)' pages/api/ 2>/dev/null || true)
|
||||||
|
if [ -n "$MATCHES" ]; then
|
||||||
|
echo "::error::Forbidden CORS headers present under pages/api/. Remove them — same-origin Vercel deployment does not need CORS."
|
||||||
|
echo "$MATCHES" | while IFS= read -r line; do
|
||||||
|
file=$(echo "$line" | cut -d: -f1)
|
||||||
|
lineno=$(echo "$line" | cut -d: -f2)
|
||||||
|
echo "::error file=${file},line=${lineno}::Forbidden CORS header — delete this line."
|
||||||
|
done
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "OK: no Access-Control-Allow-* headers under pages/api/."
|
||||||
|
|
||||||
test:
|
test:
|
||||||
name: Unit tests (vitest)
|
name: Unit tests (vitest)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
|
||||||
|
|
@ -242,17 +242,6 @@ async function loadLorcanaCards() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
// Set CORS headers
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
|
|
||||||
// Handle preflight requests
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.status(200).end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.method !== 'GET' && req.method !== 'POST') {
|
if (req.method !== 'GET' && req.method !== 'POST') {
|
||||||
return res.status(405).json({ error: 'Method not allowed' });
|
return res.status(405).json({ error: 'Method not allowed' });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,6 @@ import jwt from 'jsonwebtoken';
|
||||||
import { JWT_SECRET } from '../../../lib/auth-secret.js';
|
import { JWT_SECRET } from '../../../lib/auth-secret.js';
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
// Set CORS headers
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
|
|
||||||
// Handle preflight requests
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.status(200).end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.method !== 'GET') {
|
if (req.method !== 'GET') {
|
||||||
return res.status(405).json({ error: 'Method not allowed' });
|
return res.status(405).json({ error: 'Method not allowed' });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,6 @@ import { sql } from '@vercel/postgres';
|
||||||
import { getUserFromRequest } from '../../../../lib/permission-middleware';
|
import { getUserFromRequest } from '../../../../lib/permission-middleware';
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
// Set CORS headers
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.status(200).end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.method !== 'POST') {
|
if (req.method !== 'POST') {
|
||||||
return res.status(405).json({ error: 'Method not allowed' });
|
return res.status(405).json({ error: 'Method not allowed' });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,6 @@ import { sql } from '@vercel/postgres';
|
||||||
import { getUserFromRequest } from '../../../lib/permission-middleware';
|
import { getUserFromRequest } from '../../../lib/permission-middleware';
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
// Set CORS headers
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
|
|
||||||
// Handle preflight requests
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.status(200).end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.method !== 'GET') {
|
if (req.method !== 'GET') {
|
||||||
return res.status(405).json({ error: 'Method not allowed' });
|
return res.status(405).json({ error: 'Method not allowed' });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,6 @@
|
||||||
import { sql } from '@vercel/postgres';
|
import { sql } from '@vercel/postgres';
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
// Set CORS headers
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
|
|
||||||
// Handle preflight requests
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.status(200).end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.method !== 'GET') {
|
if (req.method !== 'GET') {
|
||||||
return res.status(405).json({ error: 'Method not allowed' });
|
return res.status(405).json({ error: 'Method not allowed' });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,6 @@ import { getUserFromRequest, logCollectionActivity } from '../../lib/permission-
|
||||||
import { generateUniqueSlug } from '../../lib/slug-utils';
|
import { generateUniqueSlug } from '../../lib/slug-utils';
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
// Set CORS headers
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
|
|
||||||
// Handle preflight requests
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.status(200).end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.method === 'GET') {
|
if (req.method === 'GET') {
|
||||||
try {
|
try {
|
||||||
// Get authenticated user
|
// Get authenticated user
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,6 @@ import { getUserFromRequest } from '../../../lib/permission-middleware';
|
||||||
import { isValidSlug } from '../../../lib/slug-utils';
|
import { isValidSlug } from '../../../lib/slug-utils';
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
// Set CORS headers
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'GET, PUT, DELETE, OPTIONS');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
|
|
||||||
// Handle preflight requests
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.status(200).end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Try to get authenticated user (optional for public collections)
|
// Try to get authenticated user (optional for public collections)
|
||||||
const user = await getUserFromRequest(req);
|
const user = await getUserFromRequest(req);
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,6 @@ import { getUserFromRequest } from '../../../../lib/permission-middleware';
|
||||||
import { isValidSlug } from '../../../../lib/slug-utils';
|
import { isValidSlug } from '../../../../lib/slug-utils';
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
// Set CORS headers
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
|
|
||||||
// Handle preflight requests
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.status(200).end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.method !== 'GET') {
|
if (req.method !== 'GET') {
|
||||||
return res.status(405).json({ error: 'Method not allowed' });
|
return res.status(405).json({ error: 'Method not allowed' });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,6 @@ import { getUserFromRequest } from '../../../../lib/permission-middleware';
|
||||||
import { isValidSlug } from '../../../../lib/slug-utils';
|
import { isValidSlug } from '../../../../lib/slug-utils';
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
// Set CORS headers
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
|
|
||||||
// Handle preflight requests
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.status(200).end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Try to get authenticated user (optional for public collections)
|
// Try to get authenticated user (optional for public collections)
|
||||||
const user = await getUserFromRequest(req);
|
const user = await getUserFromRequest(req);
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,6 @@ import { getUserFromRequest } from '../../../../lib/permission-middleware';
|
||||||
import { isValidSlug } from '../../../../lib/slug-utils';
|
import { isValidSlug } from '../../../../lib/slug-utils';
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
// Set CORS headers
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
|
|
||||||
// Handle preflight requests
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.status(200).end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Get authenticated user
|
// Get authenticated user
|
||||||
const user = await getUserFromRequest(req);
|
const user = await getUserFromRequest(req);
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,6 @@ import { getUserFromRequest } from '../../../../lib/permission-middleware';
|
||||||
import { isValidSlug } from '../../../../lib/slug-utils';
|
import { isValidSlug } from '../../../../lib/slug-utils';
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
// Set CORS headers
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
|
|
||||||
// Handle preflight requests
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.status(200).end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.method !== 'GET') {
|
if (req.method !== 'GET') {
|
||||||
return res.status(405).json({ error: 'Method not allowed' });
|
return res.status(405).json({ error: 'Method not allowed' });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,6 @@ import { sql } from '@vercel/postgres';
|
||||||
import { getUserFromRequest } from '../../../lib/permission-middleware';
|
import { getUserFromRequest } from '../../../lib/permission-middleware';
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
// Set CORS headers
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
|
|
||||||
// Handle preflight requests
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.status(200).end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.method !== 'GET') {
|
if (req.method !== 'GET') {
|
||||||
return res.status(405).json({ error: 'Method not allowed' });
|
return res.status(405).json({ error: 'Method not allowed' });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,6 @@ import jwt from 'jsonwebtoken';
|
||||||
import { JWT_SECRET } from '../../lib/auth-secret.js';
|
import { JWT_SECRET } from '../../lib/auth-secret.js';
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
// Set CORS headers
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, DELETE, OPTIONS');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.status(200).end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify authentication
|
// Verify authentication
|
||||||
const authHeader = req.headers.authorization;
|
const authHeader = req.headers.authorization;
|
||||||
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
if (!authHeader || !authHeader.startsWith('Bearer ')) {
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,6 @@
|
||||||
import { sql } from '@vercel/postgres';
|
import { sql } from '@vercel/postgres';
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
// Set CORS headers
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
|
|
||||||
// Handle preflight requests
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.status(200).end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.method !== 'POST') {
|
if (req.method !== 'POST') {
|
||||||
return res.status(405).json({ error: 'Method not allowed' });
|
return res.status(405).json({ error: 'Method not allowed' });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,6 @@
|
||||||
import { sql } from '@vercel/postgres';
|
import { sql } from '@vercel/postgres';
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
// Set CORS headers
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
|
|
||||||
// Handle preflight requests
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.status(200).end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.method !== 'POST') {
|
if (req.method !== 'POST') {
|
||||||
return res.status(405).json({ error: 'Method not allowed' });
|
return res.status(405).json({ error: 'Method not allowed' });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,6 @@
|
||||||
import { sql } from '@vercel/postgres';
|
import { sql } from '@vercel/postgres';
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
// Set CORS headers
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
|
|
||||||
// Handle preflight requests
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.status(200).end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.method !== 'GET') {
|
if (req.method !== 'GET') {
|
||||||
return res.status(405).json({ error: 'Method not allowed' });
|
return res.status(405).json({ error: 'Method not allowed' });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,17 +11,6 @@ export const config = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
// Set CORS headers
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'POST, DELETE, OPTIONS');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
|
|
||||||
// Handle preflight requests
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.status(200).end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Get authenticated user
|
// Get authenticated user
|
||||||
const user = await getUserFromRequest(req);
|
const user = await getUserFromRequest(req);
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,6 @@ import { sql } from '@vercel/postgres';
|
||||||
import { getUserFromRequest } from '../../../../lib/permission-middleware';
|
import { getUserFromRequest } from '../../../../lib/permission-middleware';
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
// Set CORS headers
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'POST, OPTIONS');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
|
|
||||||
// Handle preflight requests
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.status(200).end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.method !== 'POST') {
|
if (req.method !== 'POST') {
|
||||||
return res.status(405).json({ error: 'Method not allowed' });
|
return res.status(405).json({ error: 'Method not allowed' });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,6 @@ import { sql } from '@vercel/postgres';
|
||||||
import { getUserFromRequest } from '../../../lib/permission-middleware';
|
import { getUserFromRequest } from '../../../lib/permission-middleware';
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
// Set CORS headers
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'DELETE, OPTIONS');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
|
|
||||||
// Handle preflight requests
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.status(200).end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.method !== 'DELETE') {
|
if (req.method !== 'DELETE') {
|
||||||
return res.status(405).json({ error: 'Method not allowed' });
|
return res.status(405).json({ error: 'Method not allowed' });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,6 @@ import bcrypt from 'bcryptjs';
|
||||||
import { getUserFromRequest } from '../../../lib/permission-middleware';
|
import { getUserFromRequest } from '../../../lib/permission-middleware';
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
// Set CORS headers
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'PUT, OPTIONS');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
|
|
||||||
// Handle preflight requests
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.status(200).end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.method !== 'PUT') {
|
if (req.method !== 'PUT') {
|
||||||
return res.status(405).json({ error: 'Method not allowed' });
|
return res.status(405).json({ error: 'Method not allowed' });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,6 @@ import { sql } from '@vercel/postgres';
|
||||||
import { getUserFromRequest } from '../../../lib/permission-middleware';
|
import { getUserFromRequest } from '../../../lib/permission-middleware';
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
// Set CORS headers
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'GET, PUT, OPTIONS');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
|
|
||||||
// Handle preflight requests
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.status(200).end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Get authenticated user
|
// Get authenticated user
|
||||||
const user = await getUserFromRequest(req);
|
const user = await getUserFromRequest(req);
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,6 @@ import { sql } from '@vercel/postgres';
|
||||||
import { getUserFromRequest } from '../../../lib/permission-middleware';
|
import { getUserFromRequest } from '../../../lib/permission-middleware';
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
// Set CORS headers
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'GET, PUT, OPTIONS');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
|
|
||||||
// Handle preflight requests
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.status(200).end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Get authenticated user
|
// Get authenticated user
|
||||||
const user = await getUserFromRequest(req);
|
const user = await getUserFromRequest(req);
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,6 @@ import { sql } from '@vercel/postgres';
|
||||||
import { getUserFromRequest } from '../../../lib/permission-middleware';
|
import { getUserFromRequest } from '../../../lib/permission-middleware';
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
// Set CORS headers
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
|
|
||||||
// Handle preflight requests
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.status(200).end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.method !== 'GET') {
|
if (req.method !== 'GET') {
|
||||||
return res.status(405).json({ error: 'Method not allowed' });
|
return res.status(405).json({ error: 'Method not allowed' });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,6 @@ import jwt from 'jsonwebtoken';
|
||||||
import { JWT_SECRET } from '../../../lib/auth-secret.js';
|
import { JWT_SECRET } from '../../../lib/auth-secret.js';
|
||||||
|
|
||||||
export default async function handler(req, res) {
|
export default async function handler(req, res) {
|
||||||
// Set CORS headers
|
|
||||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
||||||
res.setHeader('Access-Control-Allow-Methods', 'GET, OPTIONS');
|
|
||||||
res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
|
|
||||||
|
|
||||||
if (req.method === 'OPTIONS') {
|
|
||||||
res.status(200).end();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (req.method !== 'GET') {
|
if (req.method !== 'GET') {
|
||||||
return res.status(405).json({ error: 'Method not allowed' });
|
return res.status(405).json({ error: 'Method not allowed' });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue