ident
All repositories: gitoria
6.6 KB
// components/main.hl — THE SHELL: the application header and the slot the page renders// into. All CSS is in components/styles.hl.import { navigate } from 'hl:web'import { siteName } from '../project.hl'import { accountOfSession, signOutEverywhere } from '../lib/accounts.hl'import AppHeader from '../theme/shell/app-header.hl'import MainMenu from '../theme/shell/main-menu.hl'import UserMenu from '../theme/shell/user-menu.hl'import Sidebar from '../theme/shell/app-sidebar.hl'import ContentFirst from '../theme/shell/content-first.hl'slot = null// OFFLINE (mission 046): true while the shell's probe cannot reach ident (the note under the header says so)noNetwork = false// the main menu marks the current page from the route (hybriel#197, in the server's HTML too): `route = null` is the declaration,// MainMenu reads {path, params, pattern} itself — no `current` is passedroute = nullsession = null// `/start` (start.hl, the page the service worker keeps offline) is this same shell with the account part switched off: it must// never read or ship the account, so `startPage` keeps the session unread and the menu, bell, user menu and avatar.js out of it.startPage = route != null && route.path == '/start'accountPage = !startPageshellEmail = startPage ? '' : accountOfSession(&session) != null ? accountOfSession(&session).email : ''shellIn = shellEmail != ''// the main menu: the header from 60rem, the phone's sidebar below — one list (signed in only: every page needs the account)static menu = [ { label = 'Identities' href = '/' } { label = 'Inbox' href = '/inbox' } { label = 'Apps' href = '/apps' } { label = 'Access' href = '/access' } { label = 'Docs' href = '/docs' } ]Style {inboxBell { display = 'block' flex = 'none'a { display = 'flex' alignItems = 'center' justifyContent = 'center' width = 'var(--layout-tap)' height = 'var(--layout-tap)' color = 'var(--color-text)'hover { color = 'var(--color-accent)' textDecoration = 'none' }svg { width = '1.5rem' height = '1.5rem' }}}}// THE SHELL (mission 012, phone first on the WorldAPI theme): ContentFirst for every page — ident has no list/detail// structure; a sign-in page is just the centred column without a sidebar. Signed in: theme AppHeader (brand · main menu ·// user menu) + the phone's Sidebar (☰ → the main menu). Signed out: the brand only (the page is the sign-in).View {body {AppHeader { brand = siteNameif (shellIn) { MainMenu { items = menu } }// the inbox shortcut of the approved screens (ident#27 mockups showed a coloured bell emoji; he asked for our monochrome icon style):// the same outline as the header's other icons (24 grid, currentColor, 1.8 stroke, round caps)if (shellIn) {inboxBell {a { class = "inboxlink" href = "/inbox" title = "Inbox" 'aria-label' = "Inbox"svg { viewBox = "0 0 24 24" fill = "none" stroke = "currentColor" 'stroke-width' = "1.8" 'stroke-linecap' = "round" 'stroke-linejoin' = "round" 'aria-hidden' = "true"path { d = "M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9" }path { d = "M10.3 21a1.94 1.94 0 0 0 3.4 0" }}}}}if (shellIn) {UserMenu {p { id = "whoami" class = "who" shellEmail }button { id = "menusignout" type = "button" "Sign out" on click(e) { emit shellSignOut(e) } }button { id = "menusignoutall" type = "button" "Sign out everywhere" on click(e) { emit shellSignOutAll(e) } }}}}if (noNetwork) { offlineNote { id = "offline" "Offline — ident needs the network to sign in and to save" } }// THE NETWORK PROBE: a CSS animation (components/styles.hl `ident-net-probe`) starts half a second// after the page is up and repeats every 20 s; each start and repeat asks /api/online.// A View has no "mounted" event, and a probe that fired before the page is hydrated// would be lost, so the delayed animation is the trigger. No JavaScript of ours.netProbe { on animationstart(e) { emit probe(e) } on animationiteration(e) { emit probe(e) } }if (shellIn) { Sidebar { desktop = "false" MainMenu { items = menu } } }// `Sidebar` + `main { ContentFirst { slot } }` (hybriel#130: the page slot must start its own line)main {ContentFirst { slot }}if (accountPage) { script { src = "/avatar.js" } }}}// a page's in-place sign-in (home.hl verify): its emit reaches this shell (hybriel#193), so the user menu follows at once, no reloadon shellSession(email) {shellEmail = emailshellIn = email != ''}// the user menu's Sign out: the session forgets the account, the page reloads into the sign-inon shellSignOut(e) {r = emit server shellSignOutNow()navigate('/')}on server shellSignOutNow(session) {if (session != null) { session.user = null }return true}// the user menu's Sign out everywhere (the home page has no sign-out buttons of its own any more): every device is signed out// (the audience pushes `signedOutAll` to the other open pages), this browser's session too; then the sign-in formon shellSignOutAll(e) {if (!confirm('Sign out of ident on every device?')) { return null }r = emit server shellSignOutAllNow()if (r != null && r.error == null) { navigate('/') }}on server shellSignOutAllNow(session) {me = accountOfSession(&session)if (me == null) { return { error = 'you are not signed in' } }emit client signedOutAll(me.id)session.user = nullreturn signOutEverywhere(me.id)}// the probe: no answer (or not ident's 204) = offline; the next repeat clears it again.// On `/start` (the installed app's start page, start.hl) an answer means: go on to `/`.on probe(e) {r = window.__hlAttempt(() => { return fetch('/api/online', { cache = 'no-store' }) })noNetwork = !r.ok || r.value.status != 204if (!noNetwork && route.path == '/start') {// the shell stays mounted when `/start` goes on to `/` (navigate): only now, online, it learns the account — never in `/start`'s own HTMLemail = emit server shellAccountNow()shellEmail = emailshellIn = email != ''startPage = falseaccountPage = truenavigate('/', replace = true)}}on server shellAccountNow(session) {me = accountOfSession(&session)return me != null ? me.email : ''}// "SIGN OUT EVERYWHERE" from another device or tab (home.hl signOutAll): the server pushes// this to every open page of the account (project.hl audience), which reloads into the// signed-out state at once — no click needed.on client signedOutAll(accountId) {// the page that asked for it (the user menu's own sign-out, above) has already left for the sign-in: nothing to reload thereif (shellEmail != '') {shellEmail = ''shellIn = falsenavigate(route.path, replace = true)}}
Branches
Latest commits
- 8cbc5717ident#40.3: the email step is one component (components/emailstep.hl) placed by home.hl and embed.hlmre
- 6fad3bd2Merge branch 'f3-codestep' into mainIdent
- 51e387f2|||PR ident#40 the code step is one component (components/codestep.hl) placed by home.hl and embed.hl; its verify face, setCode, browserZone and verify call exist once (#40.2)mre
- c28bddeeMerge branch 'f2-shell' into mainIdent
- c3a40ff6|||PR ident#40 one shell for the app and /start (account part off on /start, #40.1); startshell.hl removed; unused signOut faces gone (#40.4)mre
- 060f3870ident#40.4: use the shell sign-out faces in regression gatesmre
- 9b94aa6aMerge branch 'f1b-cleanup' into mainIdent
- edcfce3f|||PR ident#41 ident#43 ident#44 login error page as a component (same status codes and text, pixel-identical), declarations and route wiring cleaned upmre
- 3ac85995ident#43 ident#44: plain declarations for never-reassigned lets, one envString helper, named route functions and audience rule out of project.hlmre
- c7eef14aMerge branch 'nv1-navigate' into mainIdent
- 644f9775|||PR ident#36 navigate() instead of window.location in the shell, start shell and homemre
- 4ca2f921deploy.sh: tar --hard-dereference so backups hold no hard linksmre
- 23971fb7ident#49: media queries in the language's @media formmre
- 73f4f97dident: re-vendor to hybriel day38b (mpackdb store-open fix)mre
- aa056c03ident: a startup error prints its message before exit 1 (hybriel#247)mre
- ee37a861ident#G48: gitoria's registration gets the wildcard origin of its repo addresses at load (gate tests/gitoria-origin.mjs)mre
- dc6d486fident#27: the docs gate expects the new Access entry in the main menumre
- d277633cident#27: README: identity access and the introspect endpointmre
- e999b0d3ident#27: the Access tab — one key per identity for all its apps: give access in three steps, the overview matrix, a cell's sheet (since, last use, level, rotate, revoke), the app's check POST /api/introspect, agent identities hidden from the login picker, an inbox icon in the header's icon style (gate: tests/access.mjs)mre
- 436206fcident#47: deploy.sh runs the sign-in gate on the deploy's own port slot, like the sessionwrites and docs gates (the default 8700 can be taken by another process)mre