Compare commits

...

2 Commits

Author SHA1 Message Date
Maxi Quoß d7c4a922e2 fix scan not working #59 2023-03-07 10:03:21 +01:00
Maxi Quoß 8c4c402c2c refresh auth tokens to avoid expiration 2023-03-06 18:13:25 +01:00
2 changed files with 16 additions and 2 deletions
+11 -1
View File
@@ -10,7 +10,7 @@
let preferesDark;
let isAuth = false;
onMount(() => {
onMount(async () => {
// import bootstrap js
import('bootstrap/js/dist/dropdown');
import('bootstrap/js/dist/collapse');
@@ -38,9 +38,19 @@
isAuth = state;
});
// load auth from localstorage
const pbCookie = localStorage.getItem('pocketbase_auth');
if (pbCookie) {
$pocketbase.authStore.loadFromCookie('pb_auth=' + pbCookie);
// try to refresh auth token if valid
if ($pocketbase.authStore.isValid) {
if ($pocketbase.authStore.model?.collectionName === 'users') {
await $pocketbase.collection('users').authRefresh();
} else {
await $pocketbase.admins.authRefresh();
}
}
authorizedStore.set($pocketbase.authStore.isValid);
}
});
+5 -1
View File
@@ -81,7 +81,11 @@
buttons.scan.state = 'failed';
});
fetch(`${dev ? 'http://localhost:8090' : ''}/api/upsnap/scan`)
fetch(`${dev ? 'http://localhost:8090' : ''}/api/upsnap/scan`, {
headers: {
Authorization: $pocketbase.authStore.baseToken
}
})
.then((res) => res.json())
.then((data) => {
if (data.message) {