feat: enhance AuthService to support admin role assignment for the first user

This commit is contained in:
2026-01-06 15:42:29 -05:00
parent edd94c45e8
commit c934c85b13
2 changed files with 7 additions and 2 deletions
+6 -2
View File
@@ -12,10 +12,11 @@ using Bcrypt = BCrypt.Net.BCrypt;
namespace SharpbinV3.Server.Services
{
public sealed class AuthService(AppDbContext db, IOptions<JWTSettings> options)
public sealed class AuthService(AppDbContext db, IOptions<JWTSettings> jwtOptions, IOptions<AuthSettings> authOptions)
{
private readonly AppDbContext _db = db;
private readonly JWTSettings _jwtSettings = options.Value;
private readonly JWTSettings _jwtSettings = jwtOptions.Value;
private readonly AuthSettings _authSettings = authOptions.Value;
public async Task<User> CreateUser(string username, string password, string? email, string? displayName)
{
@@ -28,6 +29,9 @@ namespace SharpbinV3.Server.Services
UUID = Guid.CreateVersion7()
};
if (_authSettings.First_User_Admin && !await _db.Users.AnyAsync())
user.Roles = [255];
_db.Users.Add(user);
await _db.SaveChangesAsync();
return user;