Files
CollabTable/shared/packages/media-shared-assets/public/js/ui/toast.js
T
Gabriel20xxandClaude Sonnet 5 9a6ec940f7
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
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>
2026-09-01 01:34:48 +02:00

74 lines
3.1 KiB
JavaScript

(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),
};
})();