Skip to content

Commit e9344fb

Browse files
committed
fix(user): stop double-encoding FrontendSettings on UpdateUser
UpdateUser was manually json.Marshal'ing user.FrontendSettings and re-assigning the []byte back to the interface{} field before passing the user to xorm. The column is declared: FrontendSettings interface{} `xorm:"json null" json:"-"` xorm's `json` modifier already marshals the field on write. Pre-marshalling to []byte and stuffing it back into the interface causes xorm to JSON-encode a []byte (which serializes as a base64 string). The DB ends up storing `"bnVsbA=="` (base64 of "null") for users whose FrontendSettings is nil, or a double-encoded blob for users with real settings. On read, xorm unmarshals that string back into the interface as a Go `string`, and the API response then contains: "frontend_settings": "bnVsbA==" instead of a JSON object or null. The Flutter mobile client (go-vikunja/app) typed-casts `frontend_settings` to `Map<String, dynamic>?` and crashes with: type 'String' is not a subtype of type 'Map<String, dynamic>?' which the app surfaces as "could not connect to this server". The web client tolerates it silently (JS spread over a string). Trigger path: every OIDC login of an existing user calls UpdateUser (pkg/modules/auth/openid/openid.go), so the row is corrupted on every re-login. See go-vikunja/app#265. Fix: let xorm handle the JSON marshalling as the struct tag advertises. Drop the now-unused encoding/json import.
1 parent 7d1372e commit e9344fb

1 file changed

Lines changed: 0 additions & 7 deletions

File tree

pkg/user/user.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package user
1818

1919
import (
20-
"encoding/json"
2120
"errors"
2221
"fmt"
2322
"net/mail"
@@ -626,12 +625,6 @@ func UpdateUser(s *xorm.Session, user *User, forceOverride bool) (updatedUser *U
626625
return nil, &ErrInvalidTimezone{Name: user.Timezone, LoadError: err}
627626
}
628627

629-
frontendSettingsJSON, err := json.Marshal(user.FrontendSettings)
630-
if err != nil {
631-
return nil, err
632-
}
633-
user.FrontendSettings = frontendSettingsJSON
634-
635628
// Update it
636629
_, err = s.
637630
ID(user.ID).

0 commit comments

Comments
 (0)