deckhearth/pages/api/users/search.js

54 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

import { sql } from '../../../lib/sql.js';
🚀 Implemented Complete Collection Functionality Built out all requested features from top to bottom: ✅ Upload Modal for Hero Images: - Created UploadImageModal component with drag-and-drop - Support for both URL input and file upload - Live preview and validation - Integrated into collection detail page ✅ Smart TCG Tags: - Dynamic tags showing only games with cards - Properly positioned under description - Clean blue rounded styling ✅ Combined Share & Invite Modal: - Unified ShareModal replacing separate buttons - Public access toggle with community visibility - Email/member search functionality - Default viewer role for invitations - Social sharing (Twitter, Facebook, Reddit, Discord) - User search API endpoint (/api/users/search) ✅ Comprehensive Favorites System: - Database schema for cards, collections, and decks - API endpoint (/api/favorites) for CRUD operations - Real-time favorite status checking - Working toggle functionality in UI - Migration script for database setup ✅ CSV Download Functionality: - Complete card metadata export - Proper CSV formatting with escaping - All card fields included (name, set, rarity, etc.) - Automatic filename generation - Client-side download implementation 🎯 UI/UX Improvements: - Removed duplicate buttons and switches - Clean action bar with proper hierarchy - Working modals with proper state management - Error handling and loading states 🛠️ Technical Features: - JWT authentication for all endpoints - Proper database relationships and indexes - CORS headers and error handling - Optimized queries and performance All todos completed! Ready for full collection management! 🎮✨
2025-07-25 23:28:52 -04:00
import jwt from 'jsonwebtoken';
import { JWT_SECRET } from '../../../lib/auth-secret.js';
import { checkSearchRateLimit } from '../../../lib/rate-limit.js';
🚀 Implemented Complete Collection Functionality Built out all requested features from top to bottom: ✅ Upload Modal for Hero Images: - Created UploadImageModal component with drag-and-drop - Support for both URL input and file upload - Live preview and validation - Integrated into collection detail page ✅ Smart TCG Tags: - Dynamic tags showing only games with cards - Properly positioned under description - Clean blue rounded styling ✅ Combined Share & Invite Modal: - Unified ShareModal replacing separate buttons - Public access toggle with community visibility - Email/member search functionality - Default viewer role for invitations - Social sharing (Twitter, Facebook, Reddit, Discord) - User search API endpoint (/api/users/search) ✅ Comprehensive Favorites System: - Database schema for cards, collections, and decks - API endpoint (/api/favorites) for CRUD operations - Real-time favorite status checking - Working toggle functionality in UI - Migration script for database setup ✅ CSV Download Functionality: - Complete card metadata export - Proper CSV formatting with escaping - All card fields included (name, set, rarity, etc.) - Automatic filename generation - Client-side download implementation 🎯 UI/UX Improvements: - Removed duplicate buttons and switches - Clean action bar with proper hierarchy - Working modals with proper state management - Error handling and loading states 🛠️ Technical Features: - JWT authentication for all endpoints - Proper database relationships and indexes - CORS headers and error handling - Optimized queries and performance All todos completed! Ready for full collection management! 🎮✨
2025-07-25 23:28:52 -04:00
export default async function handler(req, res) {
if (req.method !== 'GET') {
return res.status(405).json({ error: 'Method not allowed' });
}
// Verify authentication
const authHeader = req.headers.authorization;
if (!authHeader || !authHeader.startsWith('Bearer ')) {
return res.status(401).json({ error: 'Authentication required' });
}
const token = authHeader.substring(7);
try {
jwt.verify(token, JWT_SECRET);
} catch (error) {
return res.status(401).json({ error: 'Invalid token' });
}
const { allowed, reset } = await checkSearchRateLimit(req);
if (!allowed) {
res.setHeader('Retry-After', Math.ceil((reset - Date.now()) / 1000));
return res.status(429).json({ error: 'Too many attempts. Try again later.' });
}
🚀 Implemented Complete Collection Functionality Built out all requested features from top to bottom: ✅ Upload Modal for Hero Images: - Created UploadImageModal component with drag-and-drop - Support for both URL input and file upload - Live preview and validation - Integrated into collection detail page ✅ Smart TCG Tags: - Dynamic tags showing only games with cards - Properly positioned under description - Clean blue rounded styling ✅ Combined Share & Invite Modal: - Unified ShareModal replacing separate buttons - Public access toggle with community visibility - Email/member search functionality - Default viewer role for invitations - Social sharing (Twitter, Facebook, Reddit, Discord) - User search API endpoint (/api/users/search) ✅ Comprehensive Favorites System: - Database schema for cards, collections, and decks - API endpoint (/api/favorites) for CRUD operations - Real-time favorite status checking - Working toggle functionality in UI - Migration script for database setup ✅ CSV Download Functionality: - Complete card metadata export - Proper CSV formatting with escaping - All card fields included (name, set, rarity, etc.) - Automatic filename generation - Client-side download implementation 🎯 UI/UX Improvements: - Removed duplicate buttons and switches - Clean action bar with proper hierarchy - Working modals with proper state management - Error handling and loading states 🛠️ Technical Features: - JWT authentication for all endpoints - Proper database relationships and indexes - CORS headers and error handling - Optimized queries and performance All todos completed! Ready for full collection management! 🎮✨
2025-07-25 23:28:52 -04:00
const { q: query } = req.query;
if (!query || query.length < 2) {
return res.status(400).json({ error: 'Query must be at least 2 characters' });
}
try {
// Search users by email (partial match)
const result = await sql`
SELECT id, email, role, created_at
FROM users
WHERE email ILIKE ${`%${query}%`}
ORDER BY email
LIMIT 10
`;
res.status(200).json({
users: result.rows
});
} catch (error) {
console.error('User search error:', error);
res.status(500).json({ error: 'Internal server error' });
}
}