Migrate auth to AuthGuard, retiring local Postgres-backed accounts
Same pattern as GameStream (commit 6a46007), adapted for CollabTable being genuinely multi-user (not single-admin): admin user management (list/create/update/delete, role reassignment, superadmin protection) is fully proxied to AuthGuard, which already enforces the same rules CollabTable checked locally. Cookie forwarding, no local session token, AUTHGUARD_URL optional (unset = auth fully disabled), transport failures always surface as errAuthGuardUnavailable rather than ever letting a request through - proven with live tests against a closed socket. CollabTable's device-sync API token feature (separate from browser sessions) is deliberately left local-only regardless of AUTHGUARD_URL, keyed by a new currentUserID helper (AuthGuard's id when enabled, the shared placeholder id 0 when disabled) - a real, functional token either way, not faked data. Real bug found and fixed: api_tokens.user_id had a hard FK into the local auth_users table, which would reject new tokens once accounts stop being written locally. Dropped the now-invalid FK. Known, accepted gap (same as GameStream): self-service profile editing for non-admin accounts is lost, since AuthGuard only exposes an admin endpoint, no self-edit. TOTP QR issuer branding now comes from AuthGuard rather than CollabTable. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a1c29728f0
commit
9a6ec940f7
48 files changed
+12401
-511
No files matched your search
@@ -0,0 +1,178 @@
|
||||
/**
|
||||
* Shared Pagination Core
|
||||
* Exposes:
|
||||
* - window.NCPagination.render(container, state, onPageChange, variant)
|
||||
* - window.NCPaginationTop.render(container, state, onPageChange)
|
||||
* - window.NCPaginationBottom.render(container, state, onPageChange)
|
||||
* onPageChange receives (page, pageSize), where pageSize is one of 12, 24, 48, or 96.
|
||||
*/
|
||||
(() => {
|
||||
if (window.NCPagination && typeof window.NCPagination.render === 'function') {
|
||||
window.NCPaginationTop = {
|
||||
render(container, state, onPageChange) {
|
||||
window.NCPagination.render(container, state, onPageChange, 'top');
|
||||
},
|
||||
};
|
||||
window.NCPaginationBottom = {
|
||||
render(container, state, onPageChange) {
|
||||
window.NCPagination.render(container, state, onPageChange, 'bottom');
|
||||
},
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
function fmtNum(n) {
|
||||
return String(Number(n) || 0).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||
}
|
||||
|
||||
const PAGE_SIZE_OPTIONS = [12, 24, 48, 96];
|
||||
const DEFAULT_PAGE_SIZE = 24;
|
||||
|
||||
const icons = {
|
||||
first:
|
||||
'<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M11 19l-7-7 7-7m8 14l-7-7 7-7" /></svg>',
|
||||
prev: '<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M15 19l-7-7 7-7" /></svg>',
|
||||
next: '<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M9 5l7 7-7 7" /></svg>',
|
||||
last: '<svg class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M13 5l7 7-7 7M5 5l7 7-7 7" /></svg>',
|
||||
};
|
||||
|
||||
function render(container, state = {}, onPageChange, variant = 'top') {
|
||||
if (!container) return;
|
||||
|
||||
const page = Math.max(1, Number(state.page) || 1);
|
||||
const pages = Math.max(1, Number(state.pages) || 1);
|
||||
const total = Math.max(0, Number(state.total) || 0);
|
||||
const requestedPageSize = Number(state.pageSize);
|
||||
const pageSize = PAGE_SIZE_OPTIONS.includes(requestedPageSize)
|
||||
? requestedPageSize
|
||||
: DEFAULT_PAGE_SIZE;
|
||||
const visible = pages > 1 || (state.total !== undefined && total > 0);
|
||||
|
||||
container.hidden = !visible;
|
||||
container.style.display = visible ? '' : 'none';
|
||||
container.classList.remove('hidden');
|
||||
container.classList.add('nc-pagination-container');
|
||||
container.classList.remove('nc-pagination-top', 'nc-pagination-bottom');
|
||||
container.classList.add(variant === 'bottom' ? 'nc-pagination-bottom' : 'nc-pagination-top');
|
||||
|
||||
if (!visible) {
|
||||
container.innerHTML = '';
|
||||
return;
|
||||
}
|
||||
|
||||
container.innerHTML = '';
|
||||
|
||||
const meta = document.createElement('div');
|
||||
meta.className = 'nc-pagination-meta';
|
||||
|
||||
const infoSpan = document.createElement('span');
|
||||
infoSpan.className = 'nc-pagination-info';
|
||||
if (state.infoText !== undefined) {
|
||||
infoSpan.textContent = state.infoText;
|
||||
} else {
|
||||
infoSpan.textContent = `Page ${fmtNum(page)} of ${fmtNum(pages)} (${fmtNum(total)} total)`;
|
||||
}
|
||||
|
||||
const pageSizeLabel = document.createElement('label');
|
||||
pageSizeLabel.className = 'nc-pagination-page-size-label';
|
||||
pageSizeLabel.textContent = 'Entries per page';
|
||||
|
||||
const pageSizeSelect = document.createElement('select');
|
||||
pageSizeSelect.className = 'nc-pagination-page-size';
|
||||
pageSizeSelect.setAttribute('aria-label', 'Entries per page');
|
||||
PAGE_SIZE_OPTIONS.forEach(size => {
|
||||
const option = document.createElement('option');
|
||||
option.value = String(size);
|
||||
option.textContent = String(size);
|
||||
option.selected = size === pageSize;
|
||||
pageSizeSelect.appendChild(option);
|
||||
});
|
||||
pageSizeSelect.addEventListener('change', () => {
|
||||
if (typeof onPageChange === 'function') onPageChange(1, Number(pageSizeSelect.value));
|
||||
});
|
||||
pageSizeLabel.appendChild(pageSizeSelect);
|
||||
meta.appendChild(infoSpan);
|
||||
meta.appendChild(pageSizeLabel);
|
||||
|
||||
const centerWrap = document.createElement('div');
|
||||
centerWrap.className = 'nc-pagination-center';
|
||||
const centerSlot = document.createElement('div');
|
||||
centerSlot.className = 'nc-pagination-center-slot';
|
||||
centerSlot.dataset.ncPaginationCenterSlot = '1';
|
||||
centerWrap.appendChild(centerSlot);
|
||||
|
||||
const btnContainer = document.createElement('div');
|
||||
btnContainer.className = 'nc-pagination-btns';
|
||||
|
||||
const buttonClass = 'nc-pagination-btn';
|
||||
const activeClass = 'nc-pagination-btn nc-pagination-btn-active';
|
||||
|
||||
const addButton = (labelHtml, targetPage, isActive, ariaLabel) => {
|
||||
const btn = document.createElement('button');
|
||||
btn.type = 'button';
|
||||
btn.innerHTML = labelHtml;
|
||||
btn.className = isActive ? activeClass : buttonClass;
|
||||
if (ariaLabel) btn.setAttribute('aria-label', ariaLabel);
|
||||
if (isActive) btn.setAttribute('aria-current', 'page');
|
||||
|
||||
const canGo = !isActive && targetPage >= 1 && targetPage <= pages && targetPage !== page;
|
||||
if (canGo) {
|
||||
btn.addEventListener('click', () => {
|
||||
if (typeof onPageChange === 'function') onPageChange(targetPage, pageSize);
|
||||
});
|
||||
} else if (!isActive) {
|
||||
btn.disabled = true;
|
||||
}
|
||||
|
||||
btnContainer.appendChild(btn);
|
||||
};
|
||||
|
||||
addButton(icons.first, 1, false, 'First page');
|
||||
addButton(icons.prev, page - 1, false, 'Previous page');
|
||||
|
||||
let start = Math.max(1, page - 2);
|
||||
let end = start + 4;
|
||||
if (end > pages) {
|
||||
end = Math.max(1, pages);
|
||||
start = Math.max(1, end - 4);
|
||||
}
|
||||
|
||||
const pageButtonCount = Math.min(5, pages);
|
||||
for (let i = 0; i < pageButtonCount; i += 1) {
|
||||
const targetPage = start + i;
|
||||
addButton(String(targetPage), targetPage, targetPage === page, `Page ${targetPage}`);
|
||||
}
|
||||
|
||||
addButton(icons.next, page + 1, false, 'Next page');
|
||||
addButton(icons.last, pages, false, 'Last page');
|
||||
|
||||
container.appendChild(meta);
|
||||
container.appendChild(centerWrap);
|
||||
container.appendChild(btnContainer);
|
||||
|
||||
container.dispatchEvent(
|
||||
new CustomEvent('nc:pagination-rendered', {
|
||||
bubbles: true,
|
||||
detail: {
|
||||
variant,
|
||||
page,
|
||||
pages,
|
||||
total,
|
||||
pageSize,
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
window.NCPagination = { render };
|
||||
window.NCPaginationTop = {
|
||||
render(container, state, onPageChange) {
|
||||
render(container, state, onPageChange, 'top');
|
||||
},
|
||||
};
|
||||
window.NCPaginationBottom = {
|
||||
render(container, state, onPageChange) {
|
||||
render(container, state, onPageChange, 'bottom');
|
||||
},
|
||||
};
|
||||
})();
|
||||
Reference in new issue
Block a user