[#215] updated the admin ui to allow displaying private files
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import PocketBase, { LocalAuthStore, Admin } from "pocketbase";
|
||||
import PocketBase, { LocalAuthStore, Admin, isTokenExpired } from "pocketbase";
|
||||
// ---
|
||||
import CommonHelper from "@/utils/CommonHelper";
|
||||
import { replace } from "svelte-spa-router";
|
||||
@@ -6,6 +6,8 @@ import { addErrorToast } from "@/stores/toasts";
|
||||
import { setErrors } from "@/stores/errors";
|
||||
import { setAdmin } from "@/stores/admin";
|
||||
|
||||
const adminFileTokenKey = "pb_admin_file_token";
|
||||
|
||||
/**
|
||||
* Clears the authorized state and redirects to the login page.
|
||||
*
|
||||
@@ -63,6 +65,29 @@ PocketBase.prototype.errorResponseHandler = function(err, notify = true, default
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @return {Promise<String>}
|
||||
*/
|
||||
PocketBase.prototype.getAdminFileToken = async function() {
|
||||
let token = localStorage.getItem(adminFileTokenKey) || '';
|
||||
|
||||
// request a new token only if the previous one is missing or will expire soon
|
||||
if (!token || isTokenExpired(token, 15)) {
|
||||
// remove previously stored token (if any)
|
||||
token && localStorage.removeItem(adminFileTokenKey);
|
||||
|
||||
if (!this._adminFileTokenRequest) {
|
||||
this._adminFileTokenRequest = this.files.getToken();
|
||||
}
|
||||
|
||||
token = await this._adminFileTokenRequest;
|
||||
localStorage.setItem(adminFileTokenKey, token);
|
||||
this._adminFileTokenRequest = null;
|
||||
}
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
// Custom auth store to sync the svelte admin store state with the authorized admin instance.
|
||||
class AppAuthStore extends LocalAuthStore {
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user