/** * Setup Admin User Script * Run this to promote the first user to admin */ import { query } from '../src/lib/auth/db' async function setupAdmin() { try { console.log('šŸ” Looking for users...') // Get all users const usersResult = await query( 'SELECT id, name, email, role FROM users ORDER BY "createdAt" ASC' ) if (usersResult.rows.length === 0) { console.log('āŒ No users found. Please create a user account first.') return } console.log('šŸ“‹ Found users:') usersResult.rows.forEach((user, index) => { console.log(`${index + 1}. ${user.name} (${user.email}) - Role: ${user.role}`) }) // Find the first non-admin user const firstUser = usersResult.rows.find(user => user.role !== 'admin') if (!firstUser) { console.log('ā„¹ļø All users are already admins.') return } console.log(`\nšŸŽÆ Promoting first user to admin: ${firstUser.name} (${firstUser.email})`) // Promote to admin await query( 'UPDATE users SET role = $1, "updatedAt" = NOW() WHERE id = $2', ['admin', firstUser.id] ) console.log('āœ… Successfully promoted user to admin!') console.log(`šŸ”‘ Admin login: ${firstUser.email}`) console.log('šŸ“ Admin dashboard: /admin') } catch (error) { console.error('āŒ Error setting up admin:', error) } finally { process.exit(0) } } // Run the script setupAdmin()