diff --git a/.gitignore b/.gitignore index a3b80670..4edf087d 100644 --- a/.gitignore +++ b/.gitignore @@ -97,3 +97,6 @@ Screenshot*.png umami-local/ ADMIN_LOGIN_INSTRUCTIONS.md scripts/reset-admin-password.js +.admin-credentials.local +scripts/reset-admin-password.js +ADMIN_LOGIN_INSTRUCTIONS.md diff --git a/public/js/admin/login.js b/public/js/admin/login.js index 8153abcc..d3a86f02 100644 --- a/public/js/admin/login.js +++ b/public/js/admin/login.js @@ -29,7 +29,7 @@ loginForm.addEventListener('submit', async (e) => { if (response.ok && data.success) { // Store token - localStorage.setItem('admin_token', data.token); + localStorage.setItem('admin_token', data.accessToken); localStorage.setItem('admin_user', JSON.stringify(data.user)); // Redirect to dashboard @@ -55,5 +55,5 @@ function showError(message) { // Auto-fill for development (optional) if (window.location.hostname === 'localhost') { - document.getElementById('email').value = 'admin@tractatus.local'; + document.getElementById('email').value = 'admin@agenticgovernance.digital'; } diff --git a/scripts/fix-admin-user.js b/scripts/fix-admin-user.js new file mode 100755 index 00000000..b7207229 --- /dev/null +++ b/scripts/fix-admin-user.js @@ -0,0 +1,52 @@ +#!/usr/bin/env node +require('dotenv').config(); + +const { connect, close, getCollection } = require('../src/utils/db.util'); +const User = require('../src/models/User.model'); + +const EMAIL = process.argv[2] || 'admin@agenticgovernance.digital'; +const PASSWORD = process.argv[3] || 'TractatusDev2025'; +const NAME = process.argv[4] || 'Admin User'; + +async function fixAdminUser() { + try { + await connect(); + + // Find existing admin user + const existing = await User.findByEmail(EMAIL); + + if (existing) { + console.log(`āœ… Found existing admin: ${existing.email} (ID: ${existing._id})`); + console.log(` Deleting...`); + await User.delete(existing._id); + console.log(`āœ… Deleted old admin user`); + } + + // Create new admin with proper password field + console.log(`\nšŸ“ Creating new admin user...`); + const admin = await User.create({ + name: NAME, + email: EMAIL, + password: PASSWORD, + role: 'admin', + active: true + }); + + console.log(`\nāœ… Admin user created successfully!`); + console.log(` Email: ${admin.email}`); + console.log(` Password: ${PASSWORD}`); + console.log(` Role: ${admin.role}`); + console.log(` ID: ${admin._id}`); + console.log(`\nšŸ” Test login at: POST /api/auth/login`); + + await close(); + process.exit(0); + + } catch (error) { + console.error('\nāŒ Error:', error.message); + await close(); + process.exit(1); + } +} + +fixAdminUser(); diff --git a/src/controllers/auth.controller.js b/src/controllers/auth.controller.js index b82218bf..b372d958 100644 --- a/src/controllers/auth.controller.js +++ b/src/controllers/auth.controller.js @@ -37,9 +37,9 @@ async function login(req, res) { res.json({ success: true, - token, + accessToken: token, user: { - id: user._id, + id: user._id.toString(), email: user.email, name: user.name, role: user.role