// auth.js — gates the whole site behind your PromptPCB account (SHARED with app.promptpcb.ai via its // SSO bridge). Nothing loads until you're signed in; the catalog + file URLs come only from the authed // Corben function, which itself verifies your PromptPCB session. (function () { var CORBEN = 'https://api.corben.world'; // Corben functions (catalog/autofill/submit) var AUTH = 'https://app.promptpcb.ai'; // shared PromptPCB accounts live here var FN_CATALOG = '0f3cd09e-81ce-43f4-88e7-cde3d91f122e'; var TK_CATALOG = '687d2466cea418815433b60946d6742a'; var LS = 'ppcb_token'; window.PPCB = { token: null, user: null }; window.ppcbReady = function (fn) { if (window.PPCB.token) fn(); else addEventListener('ppcb:auth', function () { fn(); }, { once: true }); }; window.getCatalog = async function () { var r = await fetch(CORBEN + '/functions/' + FN_CATALOG + '/invoke?token=' + TK_CATALOG, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + window.PPCB.token }, body: '{}' }); if (r.status === 401) { logout(); throw new Error('session expired'); } var d = await r.json(); return d.parts || []; }; window.ppcbAuth = function () { return { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + (window.PPCB.token || '') }; }; function authed(user) { window.PPCB.user = user; document.documentElement.classList.add('ppcb-authed'); var g = document.getElementById('ppcb-gate'); if (g) g.style.display = 'none'; var c = document.querySelector('.credits'); if (c) c.innerHTML = '◆ ' + (user.name || user.email.split('@')[0]) + ' · sign out'; var lo = document.getElementById('ppcb-logout'); if (lo) lo.onclick = function (e) { e.preventDefault(); logout(); }; dispatchEvent(new Event('ppcb:auth')); } function logout() { localStorage.removeItem(LS); location.reload(); } window.ppcbLogout = logout; async function check() { var t = localStorage.getItem(LS); if (!t) return gate(); try { var r = await fetch(AUTH + '/api/auth/sso/verify', { headers: { Authorization: 'Bearer ' + t } }); if (!r.ok) return gate(); var u = await r.json(); if (!u.valid) return gate(); window.PPCB.token = t; authed({ email: u.email, name: u.name }); } catch (e) { gate(); } } function gate() { document.documentElement.classList.remove('ppcb-authed'); if (document.getElementById('ppcb-gate')) { document.getElementById('ppcb-gate').style.display = 'flex'; return; } var el = document.createElement('div'); el.id = 'ppcb-gate'; el.innerHTML = '