Files
blackcanyontickets/setup-super-admins.js
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

99 lines
2.8 KiB
JavaScript

#!/usr/bin/env node
import { createClient } from '@supabase/supabase-js';
import { config } from 'dotenv';
// Load environment variables
config();
const supabaseUrl = process.env.SUPABASE_URL || process.env.PUBLIC_SUPABASE_URL;
const supabaseServiceKey = process.env.SUPABASE_SERVICE_KEY;
if (!supabaseUrl || !supabaseServiceKey) {
console.error('Missing required environment variables: SUPABASE_URL and SUPABASE_SERVICE_KEY');
process.exit(1);
}
const supabase = createClient(supabaseUrl, supabaseServiceKey);
const superAdminEmails = [
'tmartinez@gmail.com',
'kyle@touchofcarepcp.com'
];
async function setupSuperAdmins() {
console.log('Setting up super admin accounts...');
for (const email of superAdminEmails) {
try {
console.log(`\nProcessing: ${email}`);
// Check if user exists
const { data: existingUser, error: userError } = await supabase
.from('users')
.select('id, email, role')
.eq('email', email)
.single();
if (userError && userError.code !== 'PGRST116') {
console.error(`Error checking user ${email}:`, userError);
continue;
}
if (!existingUser) {
console.log(`User ${email} not found. Creating user record...`);
// Create user record (they need to sign up first via Supabase Auth)
const { error: createError } = await supabase
.from('users')
.insert({
email: email,
role: 'admin'
})
.select()
.single();
if (createError) {
console.error(`Error creating user ${email}:`, createError);
continue;
}
console.log(`✓ Created user record for ${email}`);
} else {
console.log(`User ${email} found. Current role: ${existingUser.role}`);
// Make user admin using the database function
const { error: adminError } = await supabase.rpc('make_user_admin', {
user_email: email
});
if (adminError) {
console.error(`Error making ${email} admin:`, adminError);
continue;
}
console.log(`✓ Made ${email} an admin`);
}
// Verify the user is now an admin
const { data: updatedUser } = await supabase
.from('users')
.select('id, email, role')
.eq('email', email)
.single();
if (updatedUser) {
console.log(`✓ Verified: ${email} is now ${updatedUser.role}`);
}
} catch (error) {
console.error(`Error processing ${email}:`, error);
}
}
console.log('\nSuper admin setup complete!');
console.log('\nNote: Users must still sign up via the frontend to create their Supabase Auth accounts.');
console.log('Once they sign up, they will automatically have admin privileges.');
}
setupSuperAdmins().catch(console.error);