Fix admin login - accept both fullName and full-name form fields

Form sends 'full-name' but server expected 'fullName'.
Now accepts both formats for compatibility.
This commit is contained in:
Mikael Westöö
2026-01-23 22:22:23 +01:00
parent dc2fd61856
commit 14a5b50fa8

View File

@@ -260,7 +260,8 @@ app.post('/api/contact', async (req, res) => {
// Admin login (creates admin on first login if none exist) // Admin login (creates admin on first login if none exist)
app.post('/api/admin/login', async (req, res) => { app.post('/api/admin/login', async (req, res) => {
try { try {
const { email, password, fullName } = req.body; const { email, password, fullName, 'full-name': fullNameHyphen } = req.body;
const name = fullName || fullNameHyphen;
if (!email || !password) { if (!email || !password) {
return res.status(400).json({ error: 'Email and password are required' }); return res.status(400).json({ error: 'Email and password are required' });
@@ -272,14 +273,14 @@ app.post('/api/admin/login', async (req, res) => {
if (isFirstAdmin) { if (isFirstAdmin) {
// Create first admin // Create first admin
if (!fullName) { if (!name) {
return res.status(400).json({ error: 'Full name is required for first admin creation' }); return res.status(400).json({ error: 'Full name is required for first admin creation' });
} }
const hashedPassword = await bcrypt.hash(password, 10); const hashedPassword = await bcrypt.hash(password, 10);
const result = await pool.query( const result = await pool.query(
'INSERT INTO admins (email, password_hash, full_name) VALUES ($1, $2, $3) RETURNING id, email, full_name', 'INSERT INTO admins (email, password_hash, full_name) VALUES ($1, $2, $3) RETURNING id, email, full_name',
[email, hashedPassword, fullName] [email, hashedPassword, name]
); );
const admin = result.rows[0]; const admin = result.rows[0];