Add admin panel restricted to a single designated account
Adds a full admin view (users + projects, with view/delete) gated server-side by ADMIN_EMAIL in server/auth.js (defaults to the site owner's account, overridable via env var for other deployments). The gate is enforced on every /api/admin/* route, not just hidden in the UI — verified a non-admin session gets 403 even when it hits the endpoints directly. Deleting a user leaves their projects in place (not cascade-deleted) so admin cleanup can't accidentally destroy someone's study data. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
37cfcd55a0
commit
7006fbf544
7 files changed
+358
-6
No files matched your search
@@ -157,4 +157,28 @@ export async function confirmMfaSetup(token) {
|
||||
/** Turns 2FA off. Requires the current password as a safety check. */
|
||||
export async function disableMfa(password) {
|
||||
return request('POST', '/auth/mfa/disable', { password });
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Admin (restricted server-side to the designated admin account)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
export async function adminListUsers() {
|
||||
return request('GET', '/admin/users');
|
||||
}
|
||||
|
||||
export async function adminDeleteUser(id) {
|
||||
return request('DELETE', `/admin/users/${id}`);
|
||||
}
|
||||
|
||||
export async function adminListProjects() {
|
||||
return request('GET', '/admin/projects');
|
||||
}
|
||||
|
||||
export async function adminGetProject(id) {
|
||||
return request('GET', `/admin/projects/${id}`);
|
||||
}
|
||||
|
||||
export async function adminDeleteProject(id) {
|
||||
return request('DELETE', `/admin/projects/${id}`);
|
||||
}
|
||||
Reference in new issue
Block a user