Change update self method to automatically merge new fields with existing user object
This commit is contained in:
parent
152a2d921b
commit
d4518073c6
|
@ -8,7 +8,7 @@
|
|||
|
||||
const updatePassword = async () => {
|
||||
try {
|
||||
await auth.updateSelf({ ...$auth.user, password })
|
||||
await auth.updateSelf({ password })
|
||||
notifications.success("Password changed successfully")
|
||||
} catch (error) {
|
||||
notifications.error("Failed to update password")
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
const updateInfo = async () => {
|
||||
try {
|
||||
await auth.updateSelf({ ...$auth.user, ...$values })
|
||||
await auth.updateSelf($values)
|
||||
notifications.success("Information updated successfully")
|
||||
} catch (error) {
|
||||
notifications.error("Failed to update information")
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
try {
|
||||
if (forceResetPassword) {
|
||||
await auth.updateSelf({
|
||||
...$auth.user,
|
||||
password,
|
||||
forceResetPassword: false,
|
||||
})
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { derived, writable } from "svelte/store"
|
||||
import { derived, writable, get } from "svelte/store"
|
||||
import api from "../../builderStore/api"
|
||||
|
||||
export function createAuthStore() {
|
||||
|
@ -50,10 +50,11 @@ export function createAuthStore() {
|
|||
await response.json()
|
||||
user.set(null)
|
||||
},
|
||||
updateSelf: async newUser => {
|
||||
updateSelf: async fields => {
|
||||
const newUser = { ...get(user), ...fields }
|
||||
const response = await api.post("/api/admin/users/self", newUser)
|
||||
if (response.status === 200) {
|
||||
user.update(state => ({ ...state, ...newUser }))
|
||||
user.set(newUser)
|
||||
} else {
|
||||
throw "Unable to update user details"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue