Files
Job-Info/frontend/auth.js
T
2025-12-12 10:52:35 -06:00

34 lines
830 B
JavaScript

// PocketBase auth bootstrap shared by pages
(function (global) {
const pb = new PocketBase('https://pocketbase.ccllc.pro');
function authHeaders() {
if (pb.authStore.isValid && pb.authStore.token) {
return { Authorization: `Bearer ${pb.authStore.token}` };
}
return {};
}
function getDisplayName() {
const model = pb.authStore.model || {};
return (
model.display_name ||
model.name ||
model.email ||
model.username ||
'Unknown'
);
}
async function ensureAuth() {
if (pb.authStore.isValid) return true;
const path = new URL(window.location.href).pathname;
if (!path.endsWith('signin.html')) {
window.location.href = 'signin.html';
}
return false;
}
global.Auth = { pb, authHeaders, ensureAuth, getDisplayName };
})(window);