mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-06 05:57:35 +03:00
fix(server): first user created should be admin, when using reverse proxy
Fix #3902 Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
parent
2b84c574ba
commit
c01eea8224
2 changed files with 55 additions and 1 deletions
|
@ -292,13 +292,17 @@ func handleLoginFromHeaders(ds model.DataStore, r *http.Request) map[string]inte
|
|||
user, err := userRepo.FindByUsernameWithPassword(username)
|
||||
if user == nil || err != nil {
|
||||
log.Info(r, "User passed in header not found", "user", username)
|
||||
// Check if this is the first user being created
|
||||
count, _ := userRepo.CountAll()
|
||||
isFirstUser := count == 0
|
||||
|
||||
newUser := model.User{
|
||||
ID: id.NewRandom(),
|
||||
UserName: username,
|
||||
Name: username,
|
||||
Email: "",
|
||||
NewPassword: consts.PasswordAutogenPrefix + id.NewRandom(),
|
||||
IsAdmin: false,
|
||||
IsAdmin: isFirstUser, // Make the first user an admin
|
||||
}
|
||||
err := userRepo.Put(&newUser)
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue