diff --git a/admin.html b/admin.html index 34d9dab..3f2894b 100644 --- a/admin.html +++ b/admin.html @@ -540,9 +540,20 @@ ${(u.credits || 0).toLocaleString()} ${formatDate(u.created_at)} - +
+ + ${u.role === 'admin' ? ` + + ` : ` + + `} +
`).join(''); @@ -599,6 +610,40 @@ } } + async function toggleAdmin(userId, newRole) { + const user = users.find(u => u.id === userId); + const userName = user?.name || user?.email || 'this user'; + + const action = newRole === 'admin' ? 'promote' : 'demote'; + if (!confirm(`Are you sure you want to ${action} ${userName} to ${newRole}?`)) { + return; + } + + const token = await moxieAuth.getToken(); + + try { + const response = await fetch(`/api/users/${userId}/role`, { + method: 'PUT', + headers: { + 'Authorization': `Bearer ${token}`, + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ role: newRole }) + }); + + const data = await response.json(); + + if (data.success) { + await loadUsers(); + } else { + alert('Failed to update role: ' + data.message); + } + } catch (error) { + console.error('Role update error:', error); + alert('Failed to update role'); + } + } + function switchTab(tab) { currentTab = tab;