Files
evig/scripts/setup-admin.ts
T
Your Name 148d91a1b7 Update Dockerfile and TypeScript definitions; enhance health check and user role management
- Added curl to Dockerfile for health check improvements.
- Modified npm install commands to build TypeScript and prune unnecessary packages.
- Updated health check command to use curl for better reliability.
- Adjusted TypeScript definitions for user-related functions to return more specific response types.
- Changed user role options from 'viewer' to 'user' in multiple places for consistency.
- Updated package.json dependencies, including downgrading jsonwebtoken types and switching bcrypt to bcryptjs for compatibility.
- Added new environment variables for email configuration in the env.template file.
- Cleaned up various files by removing unnecessary newlines and ensuring consistent formatting.
2025-12-16 16:11:35 +01:00

62 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 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()