fix: admin/accounts: not saving if starting empty
Massimo Melina committed
May 14, 2022 at 22:29 UTC
41c69f71c1b59537a82305c7fd413fb44781e679
1 file changed
+6
-3
server/src/perm.ts
+6
-3
@@ -85,7 +85,8 @@ export async function updateAccount(account: Account, changer?:Changer) {
85
86
const saveAccountsAsap = saveConfigAsap
87
88
-defineConfig<Accounts>('accounts', {}).sub(async v => {
88
+const accountsConfig = defineConfig<Accounts>('accounts', {})
89
+accountsConfig.sub(async v => {
90
// we should validate content here
91
accounts = v // keep local reference
92
await Promise.all(_.map(accounts, async (rec,k) => {
@@ -134,7 +135,8 @@ export function addAccount(username: string, props: Partial<Account>) {
135
return
136
const copy = _.pickBy(_.pick(props, assignableProps), Boolean)
137
setHidden(copy, { username })
137
- accounts[username] = copy as typeof copy & { username: string }
138
+ accountsConfig.set(accounts =>
139
+ Object.assign(accounts, { [username]: copy }))
140
saveAccountsAsap()
141
return copy
142
}
@@ -154,7 +156,8 @@ export function setAccount(username: string, changes: Partial<Account>) {
156
export function delAccount(username: string) {
157
if (!getAccount(username))
158
return false
157
- delete accounts[username]
159
+ accountsConfig.set(accounts =>
160
+ Object.assign(accounts, { [username]: undefined }))
161
saveAccountsAsap()
162
return true
163
}