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