mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: enhance AuthService to support admin role assignment for the first user
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user