gitoria
All repositories: gitoria
3.0 KB
// login.js — the small bridge between ident's <ident-selector> and gitoria's shell (components/main.hl;// gitoria#14, the same as tickets' login.js). Plain JS because hl:web cannot listen to a custom DOM event:// `ident-login` (event.detail.code, the one-time code) goes into the hidden input #identcode, whose `change`// the shell handles (→ face gitoriaLogin, server-side exchange). The shell keeps the selector element's class// at `in` / `out`; it is mirrored here into the selector's `loggedIn` (false = back to "choose ident").// ident answers the selector only for a REGISTERED origin — the main address and (the wildcard origin) every repo address.// BACK TO THE PAGE: the "Log in with ident" click gets `?next=<this page>` in its return URL — a path on the main// address, the full URL on a repo address (project.hl safeNext checks both). At the click, so it is the page the// address bar shows after any hl:web navigation.// RUNS ONCE PER DOCUMENT: hl:web re-creates the header and its <script>s when the login state flips, the// selector element is then a NEW one; listeners sit on `document`, the CURRENT #selector is looked up each// time, and a one-time code is handed to the shell at most once.(() => {if (window.__gitoriaLogin) { window.__gitoriaLogin.sync(); return; }const sync = () => {const sel = document.getElementById('selector');// not upgraded yet: a property set now would shadow the element's own accessorif (!sel || !window.customElements || !customElements.get('ident-selector')) return;const want = sel.classList.contains('in');if (sel.loggedIn !== want) sel.loggedIn = want;};new MutationObserver(sync).observe(document.documentElement, { subtree: true, childList: true, attributes: true, attributeFilter: ['class'] });if (window.customElements) customElements.whenDefined('ident-selector').then(sync);const handed = new Set();document.addEventListener('ident-login', (e) => {const code = e.detail && e.detail.code;const input = document.getElementById('identcode');if (!input || !code || handed.has(code)) return; // a one-time code is exchanged oncehanded.add(code);input.value = code;input.dispatchEvent(new Event('change', { bubbles: true }));});const withNext = (a) => {try {const u = new URL(a.href);const ret = new URL(u.searchParams.get('return'));const main = ret.host === location.host;const here = main ? location.pathname + location.search : location.href;ret.search = '';if (here !== '/' && here.length <= 500) ret.searchParams.set('next', here);u.searchParams.set('return', ret.href);a.href = u.href;} catch (err) { /* keep the server's href: the login still works, it returns to / */ }};const onButton = (e) => {const a = e.target && e.target.closest && e.target.closest('#loginbutton');if (a) withNext(a);};for (const t of ['click', 'auxclick', 'contextmenu']) document.addEventListener(t, onButton, true);window.__gitoriaLogin = { sync };})();
Branches
- f1-broken-json
- f2-api-bugs
- gp-gate-ports
- heap-revert
- hl25-records
- ident-chooser-selector
- mainmain branch
- p51-public-pr-reads
- records-1112
- s25-no-session-on-login-error
- v59
- w52-person-approval
- w52b-approval-followup
- w52c-header-phone
- w53-pulls-speed-pr
- w54-repo-rename-pr
- w55-rename-org
- w56-owner-members
- w62-pr-close
- w63-force-push
- w64-org-slash
Latest commits
- 9feebbd3Re-vendor Hybriel to ded47c13 (W145: Firefox start script fix)mre
- 28ed41e5gitoria#24: one sign-in comes from hl:web batch 20, the /session/share workaround is gonemre
- 3b2669e4gs: drop the unbuildable legacy check, fix pwa fetchmre
- 2a2fdd77gs: C2 check before cookie experimentsmre
- 76e0587aWIP gs 2mre
- a80da7bdWIP gs: security gate for lazy sessions, g24 browser checksmre
- 23fb05d8re-vendor Hybriel aaa39e69 (hl:web batch 20: login emit and Sessions.mint, tab follows a login, signed-in session cookie wins among duplicates and is re-issued with the Domain, W85 faster render, lazy sessions)mre
- a0727ca3ident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
- a06975f9gitoria: a gap between your name and Log out in the phone header (they touched); gate checks itmre
- 32ba9d59gitoria: leave the host-only cookie experiment out of the browser gate (gitoria#24 is a separate mission)mre
- 43ad2bcfgitoria header: the selector alone plus your name and Log out as before the theme missions; tests follow (WIP: host-only cookie experiment fails)mre
- ac2c4e3fident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mre
- b279f536theme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre
- 2b01515ctests/ticketskit: a failed start kills the tickets server (own process group); stop() kills the groupmre
- 109cfc5ctests/ticketskit: keep the rotated session cookie of the tickets login (tickets ST2 session rotation)mre
- 7eb6be27sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
- b3911918reports/MG-mobile.md: 404 fixed, rebased gatesMG
- 9da65b42tests/browser.mjs: 404 checks (host, no hydration wait)MG
- 00517fafgitoria: shell 404 page for unknown paths (catch-all route, status 404, JSON 404 under /api), 390 gate checksMG
- d9e977f0reports/MG-mobile.md, LOGMG