fix avatar update

This commit is contained in:
seriousm4x
2023-08-14 00:40:36 +02:00
parent 541e8b3d8b
commit 2d6cf95647
2 changed files with 6 additions and 9 deletions

View File

@@ -72,7 +72,6 @@
});
} else {
await $pocketbase.admins.authRefresh().catch(() => {
$pocketbase.authStore.clear();
goto('/login');
});
}

View File

@@ -23,23 +23,21 @@
function changeAvatar() {
if ($isAdmin) {
if (!$pocketbase.authStore.model?.id) return;
$pocketbase.admins
.authRefresh()
.then((data) => {
data.admin.avatar = newAvatar;
$pocketbase.authStore.save(data.token, data.admin);
.update($pocketbase.authStore.model.id, { avatar: newAvatar })
.then(() => {
toast.success('Avatar saved.');
})
.catch((err) => {
toast.error(err.message);
});
} else {
if (!$pocketbase.authStore.model?.id) return;
$pocketbase
.collection('users')
.authRefresh()
.then((data) => {
data.record.avatar = newAvatar;
$pocketbase.authStore.save(data.token, data.record);
.update($pocketbase.authStore.model.id, { avatar: newAvatar })
.then(() => {
toast.success('Avatar saved.');
})
.catch((err) => {