Files
blackcanyontickets/src/pages/api/admin/setup-super-admin.ts
dzinesco 26a87d0d00 feat: Complete platform enhancement with multi-tenant architecture
Major additions:
- Territory manager system with application workflow
- Custom pricing and page builder with Craft.js
- Enhanced Stripe Connect onboarding
- CodeReadr QR scanning integration
- Kiosk mode for venue sales
- Super admin dashboard and analytics
- MCP integration for AI-powered operations

Infrastructure improvements:
- Centralized API client and routing system
- Enhanced authentication with organization context
- Comprehensive theme management system
- Advanced event management with custom tabs
- Performance monitoring and accessibility features

Database schema updates:
- Territory management tables
- Custom pages and pricing structures
- Kiosk PIN system
- Enhanced organization profiles
- CodeReadr integration tables

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-12 18:21:40 -06:00

78 lines
1.9 KiB
TypeScript

import type { APIRoute } from 'astro';
import { requireAdmin } from '../../../lib/auth';
import { supabase } from '../../../lib/supabase';
export const POST: APIRoute = async ({ request }) => {
try {
// Verify admin authentication
const auth = await requireAdmin(request);
const { email } = await request.json();
if (!email) {
return new Response(JSON.stringify({
success: false,
error: 'Email is required'
}), {
status: 400,
headers: { 'Content-Type': 'application/json' }
});
}
// Check if user exists
const { data: existingUser } = await supabase
.from('users')
.select('id, email, role')
.eq('email', email)
.single();
if (!existingUser) {
return new Response(JSON.stringify({
success: false,
error: 'User not found. User must be registered first.'
}), {
status: 404,
headers: { 'Content-Type': 'application/json' }
});
}
// Make user admin using the database function
const { error } = await supabase.rpc('make_user_admin', {
user_email: email
});
if (error) {
return new Response(JSON.stringify({
success: false,
error: 'Failed to make user admin'
}), {
status: 500,
headers: { 'Content-Type': 'application/json' }
});
}
return new Response(JSON.stringify({
success: true,
message: `Successfully made ${email} an admin`,
user: {
id: existingUser.id,
email: existingUser.email,
role: 'admin'
}
}), {
status: 200,
headers: { 'Content-Type': 'application/json' }
});
} catch (error) {
return new Response(JSON.stringify({
success: false,
error: 'Access denied or server error'
}), {
status: 500,
headers: { 'Content-Type': 'application/json' }
});
}
};