Files
panel/scripts/create-admin.js
RKWojs c1bb4c44fd feat: upgrade next-auth to v5.0.0-beta.29 and refactor authentication middleware
- Updated next-auth dependency in package.json to version 5.0.0-beta.29.
- Refactored create-admin script to use a valid email format.
- Implemented authentication middleware for various API routes to enforce access control.
- Refactored API route handlers to improve readability and maintainability.
- Enhanced error handling in authentication error page.
- Added detailed tests for authentication flow, including protected routes and NextAuth endpoints.
2025-06-25 12:32:13 +02:00

35 lines
1.0 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.

import { createUser } from "../src/lib/userManagement.js"
import initializeDatabase from "../src/lib/init-db.js"
async function createInitialAdmin() {
try {
// Initialize database first
initializeDatabase()
console.log("Creating initial admin user...")
const adminUser = await createUser({
name: "Administrator",
email: "admin@localhost.com",
password: "admin123456", // Change this in production!
role: "admin"
})
console.log("✅ Initial admin user created successfully!")
console.log("📧 Email: admin@localhost.com")
console.log("🔑 Password: admin123456")
console.log("⚠️ Please change the password after first login!")
console.log("👤 User ID:", adminUser.id)
} catch (error) {
if (error.message.includes("already exists")) {
console.log(" Admin user already exists. Skipping creation.")
} else {
console.error("❌ Error creating admin user:", error.message)
process.exit(1)
}
}
}
createInitialAdmin()