WFDASH-WEBAPP/public/pos/pos-config.js
2026-08-31 01:42:24 +02:00

28 lines
1 KiB
JavaScript

// POS config — no PocketBase credentials here. The device only knows
// its own API key for this app's /api/v1/pos/* routes; PocketBase
// auth happens server-side (see src/lib/server/pocketbase-admin.ts).
window.POS_CONFIG = (function () {
const STORAGE_KEY = "pos.apiKey";
let apiKey = localStorage.getItem(STORAGE_KEY) || "";
if (!apiKey) {
apiKey = window.prompt("Enter this till's POS API key (ask the office for it):") || "";
if (apiKey) localStorage.setItem(STORAGE_KEY, apiKey);
}
return { apiBase: "/api/v1/pos", apiKey };
})();
window.posFetch = async function (path, opts = {}) {
const cfg = window.POS_CONFIG;
const headers = Object.assign(
{ Authorization: "Bearer " + cfg.apiKey },
opts.headers || {},
);
return fetch(cfg.apiBase + path, Object.assign({}, opts, { headers }));
};
// A wrong key is worth surfacing loudly — otherwise every screen just
// silently shows "Offline" and staff assume the network is down.
window.posClearApiKey = function () {
localStorage.removeItem("pos.apiKey");
location.reload();
};