Kavita/API/Controllers/AdminController.cs
Joe Milazzo 9f29fa593d
Progress Overhaul + Profile Page and a LOT more! (#4262)
Co-authored-by: Amelia <77553571+Fesaa@users.noreply.github.com>
Co-authored-by: Robbie Davis <robbie@therobbiedavis.com>
2025-12-09 10:00:11 -07:00

30 lines
784 B
C#

using System.Threading.Tasks;
using API.Constants;
using API.Entities;
using API.Middleware;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
namespace API.Controllers;
#nullable enable
public class AdminController(UserManager<AppUser> userManager) : BaseApiController
{
/// <summary>
/// Checks if an admin exists on the system. This is essentially a check to validate if the system has been set up.
/// </summary>
/// <returns></returns>
[AllowAnonymous]
[SkipDeviceTracking]
[HttpGet("exists")]
public async Task<ActionResult<bool>> AdminExists()
{
var users = await userManager.GetUsersInRoleAsync(PolicyConstants.AdminRole);
return users.Count > 0;
}
}