Refactor startup user creation and add HomeSection config

Refactored user initialization to always ensure at least one user exists at startup. If no users are present, a default admin user (admin/jellyfin) is created automatically. Updated StartupController endpoints to handle cases where no user exists. Simplified UserManager.InitializeAsync logic. Added HomeSectionConfiguration for EF Core entity mapping. Includes minor project and assembly info updates.
This commit is contained in:
2026-02-23 17:54:53 -05:00
parent 534b0cde91
commit 43cdbf9b35
11 changed files with 78 additions and 29 deletions
@@ -542,24 +542,18 @@ namespace Jellyfin.Server.Implementations.Users
/// <inheritdoc />
public async Task InitializeAsync()
{
// TODO: Refactor the startup wizard so that it doesn't require a user to already exist.
// If no users exist, create the default admin user
if (_users.Any())
{
return;
}
var defaultName = Environment.UserName;
if (string.IsNullOrWhiteSpace(defaultName) || !ValidUsernameRegex().IsMatch(defaultName))
{
defaultName = "MyJellyfinUser";
}
_logger.LogWarning("No users, creating one with username {UserName}", defaultName);
_logger.LogWarning("No users found, creating default admin user with username 'admin'");
var dbContext = await _dbProvider.CreateDbContextAsync().ConfigureAwait(false);
await using (dbContext.ConfigureAwait(false))
{
var newUser = await CreateUserInternalAsync(defaultName, dbContext).ConfigureAwait(false);
var newUser = await CreateUserInternalAsync("admin", dbContext).ConfigureAwait(false);
newUser.SetPermission(PermissionKind.IsAdministrator, true);
newUser.SetPermission(PermissionKind.EnableContentDeletion, true);
newUser.SetPermission(PermissionKind.EnableRemoteControlOfOtherUsers, true);
@@ -578,6 +572,11 @@ namespace Jellyfin.Server.Implementations.Users
.ConfigureAwait(false);
_users.Add(reloadedUser.Id, reloadedUser);
// Set the default password "jellyfin"
await ChangePassword(reloadedUser, "jellyfin").ConfigureAwait(false);
_logger.LogWarning("Default admin user created with username 'admin' and password 'jellyfin'");
}
}