Migrate auth to AuthGuard, retiring local Postgres-backed accounts
Lint / Lint (push) Failing after 32s
Tests / Go backend (push) Successful in 54s
Tests / Dashboard checks (push) Successful in 51s
Docker / Docker Build & Push (push) Successful in 5m14s

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:
Gabriel20xxandClaude Sonnet 5 committed 2026-09-01 01:34:48 +02:00
1 parent a1c29728f0
commit 9a6ec940f7
48 files changed
+12401 -511

No files matched your search

@@ -0,0 +1,184 @@
// Shared confirm dialog utility — matches the dark design language of the monorepo.
// Usage: const ok = await NCConfirm.show({ title, message, confirmLabel, cancelLabel, danger });
// Returns a Promise<boolean>: true = confirmed, false = cancelled.
(function (global) {
if (global.NCConfirm) return;
const DIALOG_ID = 'nc-confirm-dialog';
function ensureDialog() {
let dialog = document.getElementById(DIALOG_ID);
if (dialog) return dialog;
dialog = document.createElement('div');
dialog.id = DIALOG_ID;
dialog.setAttribute('role', 'dialog');
dialog.setAttribute('aria-modal', 'true');
dialog.setAttribute('hidden', '');
dialog.style.display = 'none';
// Backdrop + centering
dialog.className = 'fixed inset-0 z-[10100] flex items-center justify-center p-4';
dialog.style.background = 'rgba(0,0,0,0.65)';
dialog.style.backdropFilter = 'blur(2px)';
dialog.innerHTML = `
<div
id="nc-confirm-panel"
class="w-full max-w-sm rounded-lg border border-slate-700 bg-slate-900 p-4 shadow-2xl"
role="document"
>
<h2
id="nc-confirm-title"
class="mb-2 text-base font-semibold text-white"
></h2>
<p
id="nc-confirm-message"
class="mb-4 text-sm leading-relaxed text-slate-300"
></p>
<div class="flex justify-end gap-3">
<button
id="nc-confirm-cancel"
type="button"
class="inline-flex items-center rounded-lg border border-slate-600 px-4 py-2 text-sm font-medium text-slate-300 transition hover:bg-slate-800 focus:outline-none focus:ring-2 focus:ring-blue-300/20"
></button>
<button
id="nc-confirm-ok"
type="button"
class="inline-flex items-center rounded-lg px-4 py-2 text-sm font-medium text-white transition focus:outline-none focus:ring-2 focus:ring-offset-1 focus:ring-offset-slate-900"
></button>
</div>
</div>
`;
document.body.appendChild(dialog);
return dialog;
}
let _resolve = null;
let _lastActive = null;
function focusables(dialog) {
return [
...dialog.querySelectorAll(
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
),
].filter(el => !el.disabled && el.offsetParent !== null);
}
function onKeyDown(e) {
const dialog = document.getElementById(DIALOG_ID);
if (!dialog || dialog.style.display === 'none') return;
if (e.key === 'Escape') {
e.preventDefault();
close(false);
return;
}
if (e.key === 'Tab') {
const els = focusables(dialog);
if (!els.length) return;
const first = els[0];
const last = els[els.length - 1];
if (e.shiftKey && document.activeElement === first) {
e.preventDefault();
last.focus();
} else if (!e.shiftKey && document.activeElement === last) {
e.preventDefault();
first.focus();
}
}
}
function close(result) {
const dialog = document.getElementById(DIALOG_ID);
if (dialog) {
dialog.style.display = 'none';
}
document.removeEventListener('keydown', onKeyDown);
if (_lastActive && typeof _lastActive.focus === 'function') {
try {
_lastActive.focus();
} catch {
/* ignore */
}
}
_lastActive = null;
if (_resolve) {
const r = _resolve;
_resolve = null;
r(result);
}
}
function show({
title = 'Confirm',
message = '',
confirmLabel = 'Confirm',
cancelLabel = 'Cancel',
danger = false,
} = {}) {
return new Promise(resolve => {
const dialog = ensureDialog();
document.getElementById('nc-confirm-title').textContent = title;
document.getElementById('nc-confirm-message').textContent = message;
document.getElementById('nc-confirm-cancel').textContent = cancelLabel;
const okBtn = document.getElementById('nc-confirm-ok');
okBtn.textContent = confirmLabel;
// Danger vs primary style for confirm button
if (danger) {
okBtn.className = okBtn.className.replace(/focus:ring-\S+/g, 'focus:ring-red-500/50');
okBtn.style.background = 'var(--color-danger-strong, #ef4444)';
okBtn.onmouseover = () => {
okBtn.style.background = 'var(--color-danger-hover, #dc2626)';
};
okBtn.onmouseout = () => {
okBtn.style.background = 'var(--color-danger-strong, #ef4444)';
};
} else {
okBtn.style.background = 'var(--color-action, #2563eb)';
okBtn.onmouseover = () => {
okBtn.style.background = 'var(--color-action-hover, #1d4ed8)';
};
okBtn.onmouseout = () => {
okBtn.style.background = 'var(--color-action, #2563eb)';
};
// Reset ring class in case it was set to danger previously
const cls = okBtn.className;
if (!cls.includes('focus:ring-blue')) {
okBtn.className = cls.replace(/focus:ring-\S+/g, 'focus:ring-blue-300/50');
}
}
// Wire up resolve
_resolve = resolve;
_lastActive = document.activeElement;
// Re-attach listeners (removes stale ones first)
const cancelBtn = document.getElementById('nc-confirm-cancel');
const freshCancel = cancelBtn.cloneNode(true);
cancelBtn.parentNode.replaceChild(freshCancel, cancelBtn);
const freshOk = okBtn.cloneNode(true);
okBtn.parentNode.replaceChild(freshOk, okBtn);
// Re-query after replacement
document.getElementById('nc-confirm-cancel').addEventListener('click', () => close(false));
document.getElementById('nc-confirm-ok').addEventListener('click', () => close(true));
document.addEventListener('keydown', onKeyDown);
dialog.style.display = '';
// Move focus to confirm button after paint
setTimeout(() => {
const btn = document.getElementById('nc-confirm-ok');
if (btn) btn.focus();
}, 10);
});
}
global.NCConfirm = { show };
})(window);
@@ -0,0 +1,142 @@
// Shared overlay + live region utilities
// Pattern centralization to avoid repetition across admin pages.
// Usage: const ov = createOverlayController({ overlayId:'mediaOverlay', liveId:'mediaLive', showDelay:250 });
// Then ov.runWithOverlay(async ()=> { ...loading work... });
// Provide announce(msg) for polite updates and announceError(msg) for errors (also logs console + optional toast).
(function (global) {
function createOverlayController({
overlayId,
liveId,
showDelay = 250,
toast,
focusSelector,
restoreFocus = true,
escToClose = true,
trapFocus = true,
} = {}) {
const overlay = document.getElementById(overlayId);
const live = document.getElementById(liveId);
let timer;
let lastActive = null;
function moveFocusIn() {
if (!overlay) return;
let target = null;
if (focusSelector) {
target = overlay.querySelector(focusSelector);
}
if (!target) {
// find first focusable
target = overlay.querySelector(
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
);
}
if (target && typeof target.focus === 'function') {
try {
target.focus();
} catch {
/* ignore focus error */
}
}
}
function showSoon() {
clearTimeout(timer);
timer = setTimeout(() => {
if (!overlay) return;
if (restoreFocus) {
lastActive = document.activeElement;
}
if (!overlay.getAttribute('role')) overlay.setAttribute('role', 'dialog');
overlay.setAttribute('aria-modal', 'true');
overlay.removeAttribute('hidden');
overlay.classList.add('is-active');
overlay.setAttribute('aria-hidden', 'false');
console.info('[ACTION] overlay_show', overlayId);
// Slight defer to allow rendering
setTimeout(moveFocusIn, 10);
}, showDelay);
}
function hide() {
clearTimeout(timer);
if (!overlay) return;
overlay.classList.remove('is-active');
overlay.setAttribute('aria-hidden', 'true');
overlay.setAttribute('hidden', '');
console.info('[ACTION] overlay_hide', overlayId);
if (restoreFocus && lastActive && typeof lastActive.focus === 'function') {
try {
lastActive.focus();
} catch {
/* ignore */
}
lastActive = null;
}
}
function onKey(e) {
if (!overlay || overlay.hasAttribute('hidden')) return;
if (e.key === 'Escape' && escToClose) {
// Attempt to refocus original trigger immediately after hiding
const trigger = lastActive;
hide();
if (trigger && typeof trigger.focus === 'function') {
try {
trigger.focus();
} catch {
/* ignore */
}
}
return;
}
if (trapFocus && e.key === 'Tab') {
const focusables = [
...overlay.querySelectorAll(
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
),
].filter(el => !el.disabled && el.offsetParent !== null);
if (focusables.length) {
const first = focusables[0];
const last = focusables[focusables.length - 1];
if (e.shiftKey && document.activeElement === first) {
e.preventDefault();
last.focus();
} else if (!e.shiftKey && document.activeElement === last) {
e.preventDefault();
first.focus();
}
}
}
}
document.addEventListener('keydown', onKey);
function announce(msg) {
if (live) {
live.textContent = msg;
}
}
function announceError(msg) {
if (live) {
live.textContent = msg;
}
if (toast && toast.error) {
toast.error(msg);
}
console.error('[OVERLAY_ERROR]', msg);
}
async function runWithOverlay(fn) {
showSoon();
try {
const r = await fn();
hide();
return r;
} catch (e) {
hide();
announceError(e.message || 'Load failed');
throw e;
}
}
function destroy() {
document.removeEventListener('keydown', onKey);
}
return { showSoon, hide, announce, announceError, runWithOverlay, destroy };
}
global.NCOverlay = { createOverlayController };
})(window);
@@ -0,0 +1,133 @@
// NCProgressBar - shared horizontal progress bar component
// Served at /shared/js/ui/progress-bar.js by applySharedBase.
//
// The 'progress-shimmer' CSS class (defined in index.css) drives the animated
// gradient fill used during indeterminate/in-progress states.
//
// API:
// const {track, fill} = NCProgressBar.create([opts]) -> builds DOM pair (NOT inserted)
// NCProgressBar.set(fill, pct, [opts]) -> set fill to pct (0-100); opts.shimmer=bool
// NCProgressBar.setShimmer(fill, on) -> add/remove 'progress-shimmer' class
//
// create() opts:
// height : CSS height utility class from index.css (default 'h-2')
// rounded : CSS rounded utility class from index.css (default 'rounded-full')
// trackClass : CSS bg utility class for the track (default 'bg-slate-800')
// fillClass : CSS bg utility class for the fill (default 'bg-[var(--color-action)]')
// shimmer : bool - start with shimmer on (default false)
(function (global) {
'use strict';
/**
* Build a progress-bar track+fill pair without inserting into DOM.
* @param {object} [opts]
* @returns {{ track: HTMLElement, fill: HTMLElement }}
*/
function create(opts) {
opts = opts || {};
var height = opts.height || 'h-2';
var rounded = opts.rounded || 'rounded-full';
var trackCls = opts.trackClass || 'bg-slate-800';
var fillCls = opts.fillClass || 'bg-[var(--color-action)]';
var shimmer = !!opts.shimmer;
var track = document.createElement('div');
track.className = [height, rounded, trackCls, 'overflow-hidden'].join(' ');
var fill = document.createElement('div');
fill.className = ['h-full', rounded, fillCls, 'transition-[width]', 'duration-300'].join(' ');
if (shimmer) fill.classList.add('progress-shimmer');
fill.style.width = '0%';
track.appendChild(fill);
return { track: track, fill: fill };
}
/**
* Toggle the shimmer animation on a fill element.
* @param {Element} fillEl
* @param {boolean} on
*/
function setShimmer(fillEl, on) {
if (!fillEl) return;
if (on) fillEl.classList.add('progress-shimmer');
else fillEl.classList.remove('progress-shimmer');
}
/**
* Set the fill width percentage (clamped 0-100).
* @param {Element} fillEl
* @param {number} pct 0-100
* @param {object} [opts] opts.shimmer - if boolean, also toggle shimmer
*/
function set(fillEl, pct, opts) {
if (!fillEl) return;
var clamped = Math.max(0, Math.min(100, Number(pct) || 0));
fillEl.style.width = clamped + '%';
if (opts && typeof opts.shimmer === 'boolean') setShimmer(fillEl, opts.shimmer);
}
/**
* Renders a highly styled processing progress bar into the specified container.
* Useful for showing download or generation progress with a label.
* @param {HTMLElement} container - DOM element to render into
* @param {object} [opts] - opts.barId, opts.labelId, opts.metaId, opts.statusDotId, opts.statusTextId, opts.statusText
*/
function renderProcessingContainer(container, opts) {
if (!container) return;
opts = opts || {};
var barId = opts.barId || 'processingProgressBar';
var labelId = opts.labelId || 'processingProgressLabel';
var metaId = opts.metaId || '';
var statusDotId = opts.statusDotId || '';
var statusTextId = opts.statusTextId || '';
var statusText = opts.statusText || 'ComfyUI: checking\u2026';
var metaHtml = metaId
? '<div id="' +
metaId +
'" class="mt-2 text-center text-xs text-[var(--color-text-dim)] empty:hidden"></div>'
: '';
var barTrackHtml = `<div class="relative h-5 w-full bg-slate-900 overflow-hidden rounded-md border border-slate-800 shadow-inner">
<div
id="${barId}"
class="h-full w-0 bg-[var(--color-action)] transition-[width] duration-200 ease-in-out"
></div>
<div
id="${labelId}"
class="pointer-events-none absolute inset-0 flex items-center justify-center text-xs font-bold uppercase tracking-widest text-[#fff] [text-shadow:0_1px_2px_rgba(0,0,0,0.8),_0_0_4px_rgba(0,0,0,0.8)] leading-none"
>
Idle
</div>
</div>`;
var statusHtml = statusDotId
? `<div class="flex items-center gap-1.5 text-[var(--font-size-xs)] text-[var(--color-text-dim)]">
<span id="${statusDotId}" class="inline-block h-2 w-2 rounded-full bg-slate-600 flex-shrink-0 transition-colors duration-300" aria-hidden="true"></span>
<span id="${statusTextId}">${statusText}</span>
</div>`
: '';
var innerHtml = statusDotId
? `<div class="flex flex-col gap-2">${barTrackHtml}${statusHtml}</div>`
: barTrackHtml;
container.innerHTML = `
<div class="rounded-lg border border-slate-800 bg-slate-900 overflow-hidden">
<div class="p-4 max-[480px]:p-3">
${innerHtml}
${metaHtml}
</div>
</div>
`;
}
global.NCProgressBar = {
create: create,
set: set,
setShimmer: setShimmer,
renderProcessingContainer: renderProcessingContainer,
};
})(window);
@@ -0,0 +1,122 @@
// NCSpinner - shared circular loading spinner component
// Served at /shared/js/ui/spinner.js by applySharedBase.
//
// API:
// NCSpinner.create([opts]) -> returns wrapper element (not inserted into DOM)
// NCSpinner.show(container, [opts]) -> inserts full-area overlay spinner; returns element
// NCSpinner.hide(el) -> removes element from DOM safely
//
// opts:
// size : 'sm'|'md'|'lg'|'xl' - maps to CSS utility class pairs in index.css (default 'lg')
// color : CSS text-color utility class from index.css (default 'text-slate-400')
// label : accessible label string (default 'Loading...')
// text : visible text string displayed below the spinner (default none)
// id : optional id attribute on the wrapper
// overlay : bool - if true (default), wrapper fills its positioned parent absolutely
(function (global) {
'use strict';
var SIZES = { sm: 'h-8 w-8', md: 'h-10 w-10', lg: 'h-12 w-12', xl: 'h-16 w-16' };
var SVG_NS = 'http://www.w3.org/2000/svg';
function makeSvg(sizeClass, color) {
var svg = document.createElementNS(SVG_NS, 'svg');
svg.setAttribute('class', 'animate-spin ' + sizeClass + ' ' + color);
svg.setAttribute('fill', 'none');
svg.setAttribute('viewBox', '0 0 24 24');
svg.setAttribute('aria-hidden', 'true');
var circle = document.createElementNS(SVG_NS, 'circle');
circle.setAttribute('class', 'opacity-25');
circle.setAttribute('cx', '12');
circle.setAttribute('cy', '12');
circle.setAttribute('r', '10');
circle.setAttribute('stroke', 'currentColor');
circle.setAttribute('stroke-width', '4');
svg.appendChild(circle);
var path = document.createElementNS(SVG_NS, 'path');
path.setAttribute('class', 'opacity-75');
path.setAttribute('fill', 'currentColor');
path.setAttribute('d', 'M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z');
svg.appendChild(path);
return svg;
}
/**
* Create a spinner wrapper element without inserting it.
* @param {object} [opts]
* @returns {HTMLElement}
*/
function create(opts) {
opts = opts || {};
var size = opts.size || 'md';
var color = opts.color || 'text-slate-400';
var label = opts.label || 'Loading\u2026';
var text = opts.text || '';
var extraCls = opts.wrapClass || '';
var sizeClass = SIZES[size] || size;
var wrap = document.createElement('div');
var flexDir = text ? 'flex-col gap-3 ' : '';
wrap.className = (
'pointer-events-none flex ' +
flexDir +
'items-center justify-center ' +
extraCls
).trim();
wrap.setAttribute('role', 'status');
wrap.setAttribute('aria-label', label);
wrap.appendChild(makeSvg(sizeClass, color));
if (text) {
var textEl = document.createElement('div');
textEl.className =
'text-xs font-semibold uppercase tracking-[0.5px] text-[var(--color-text-dim)]';
textEl.textContent = text;
wrap.appendChild(textEl);
}
return wrap;
}
/**
* Insert an overlay spinner as a child of `container` (defaults to document.body).
* @param {Element|null} container
* @param {object} [opts]
* @returns {HTMLElement} the inserted element
*/
function show(container, opts) {
opts = opts || {};
var overlay = opts.overlay !== false;
var wrapClass = overlay ? 'absolute inset-0 z-10' : '';
var el = create({
size: opts.size || 'lg',
color: opts.color || 'text-slate-400',
label: opts.label || 'Loading\u2026',
text: opts.text || '',
wrapClass: wrapClass,
});
if (opts.id) el.id = opts.id;
(container || document.body).appendChild(el);
return el;
}
/**
* Remove a spinner element previously returned by show().
* @param {Element|null} el
*/
function hide(el) {
try {
if (el && el.parentNode) el.parentNode.removeChild(el);
// eslint-disable-next-line no-empty
} catch {}
}
global.NCSpinner = { create: create, show: show, hide: hide };
})(window);
@@ -0,0 +1,73 @@
(function () {
if (window.toast) return;
const rootId = 'toast-root';
function ensureRoot() {
let el = document.getElementById(rootId);
if (!el) {
el = document.createElement('div');
el.id = rootId;
el.setAttribute('data-toast-root', '1');
el.className =
'fixed right-3 z-[10050] flex w-[min(340px,calc(100vw-1.5rem))] flex-col gap-2 hidden';
el.style.top = 'calc(var(--bar-height, 56px) + 0.75rem)';
document.body.appendChild(el);
}
return el;
}
function create(type, message, opts = {}) {
const root = ensureRoot();
const ttl = opts.duration ?? 4800;
const title =
opts.title ||
{ info: 'Info', success: 'Success', warn: 'Warning', error: 'Error' }[type] ||
'Notice';
const accent =
{
info: 'var(--color-info)',
success: 'var(--color-success)',
warn: 'var(--color-warning)',
error: 'var(--color-danger)',
}[type] || 'var(--color-accent)';
const el = document.createElement('div');
el.setAttribute('data-toast-item', '1');
el.className =
'relative isolate flex items-start gap-3 overflow-hidden rounded-md border border-[var(--color-border)] border-l-4 bg-[var(--color-surface)] px-4 py-3 text-[var(--font-size-sm)] leading-[1.3] text-[var(--color-text)] shadow-[var(--shadow-lg)]';
el.style.setProperty('--_accent', accent);
el.style.borderLeftColor = 'var(--_accent)';
el.setAttribute('role', 'status');
el.setAttribute('aria-live', 'polite');
el.innerHTML = `<div data-toast-body="1" class="flex-1 text-left"><h4 class="mb-1 text-[var(--font-size-sm)] font-semibold tracking-[0.3px]">${title}</h4><div data-toast-msg="1">${message}</div></div><button data-toast-close="1" class="absolute right-1.5 top-1.5 rounded bg-transparent p-2 text-sm leading-none text-[var(--color-text-dim)] hover:bg-[var(--color-surface-alt)] hover:text-[var(--color-text)]" aria-label="Dismiss">✕</button><div data-toast-progress="1"></div>`;
el.style.setProperty('--toast-ttl', `${ttl}ms`);
const progress = el.querySelector('[data-toast-progress]');
if (progress) {
progress.className =
'absolute bottom-0 left-0 h-[3px] w-full origin-left bg-[var(--_accent)]';
progress.style.animation = 'toast-progress linear forwards';
progress.style.animationDuration = `${ttl}ms`;
}
const closeBtn = el.querySelector('[data-toast-close]');
let closed = false;
function remove() {
if (closed) return;
closed = true;
el.style.animation = 'toast-out .35s forwards';
setTimeout(() => {
el.remove();
if (root.childElementCount === 0) root.classList.add('hidden');
}, 340);
}
closeBtn.addEventListener('click', remove);
if (ttl > 0) {
setTimeout(remove, ttl);
}
root.classList.remove('hidden');
root.appendChild(el);
return { remove };
}
window.toast = {
info: (m, o) => create('info', m, o),
success: (m, o) => create('success', m, o),
warn: (m, o) => create('warn', m, o),
error: (m, o) => create('error', m, o),
};
})();