@hollis-labs/kit-identity
v0.1.4
Published
Setup, sign-in, password, API-key and pairing-code screens and a typed client for apps on the Substrate identity module.
Maintainers
Readme
@hollis-labs/kit-identity
Setup, sign-in, password, API-key, pairing-code and active-session screens for apps built on the Substrate identity module,
plus the small typed client that talks to it. Presentational screens are controlled and fetch nothing; the client and
IdentityProvider are in a separate entry, @hollis-labs/kit-identity/client.
Builds on @hollis-labs/kit-account (ApiTokenManager, NewTokenDisclosure, SignInRequired,
SessionExpired, WhoamiBadge). Publishing is the owner's step; until the kit is in the Substrate BOM, pin the exact tag.
Use
@import "tailwindcss";
@import "@hollis-labs/design-tokens/design-tokens.css";
@import "@hollis-labs/design-components/source.css";
@import "@hollis-labs/kit-account/source.css";
@import "@hollis-labs/kit-identity/source.css";import { IdentityProvider } from '@hollis-labs/kit-identity/client'
import { IdentityGate, IDENTITY_ROUTES, IDENTITY_PAGES } from '@hollis-labs/kit-identity'
<IdentityProvider>
<IdentityGate story={<Logo />} appName="myapp">{/* the app shell, mounted only when signed in */}</IdentityGate>
</IdentityProvider>IdentityGate takes appName (the host command name; the no-owner screen shows <appName> identity setup --username NAME, with <app> if omitted). It renders boot, first-run setup (or, when the server creates the owner on the host only, a plain no-owner screen) and sign-in outside the shell (no route, no nav item) and mounts its children
only after a session exists. IDENTITY_ROUTES is the in-shell route table (/identity/account, /identity/keys,
/identity/pairing, /identity/sessions, fallback /identity/sign-out) with labels and the capability each nav item
requires ({app}.admin for keys and pairing); IDENTITY_PAGES maps the same ids to page components. Contribute the
sessions item only once a pinned version ships it. Sign out is an action: put SignOutButton in the user menu, or use
SignOutPage where the shell has no slot. SignOutPage says "Signed in as ." above the button when the
profile is known, and leaves the line out when it is not.
Contract (the client owns it; apps do not redo it)
- Paths default to
/api/setup,/api/login,/api/logout,/api/passwordand/api/identity/{profile,keys,pairing-codes,sessions}; override withbaseUrl,identityBaseandpaths(paths.profiledefaults to<identityBase>/profile). - On boot, once no setup is needed, the provider reads
GET /api/identity/profile: 200 fillsprofile,scopesand the badge (also after a reload), 401 is signed out. A host without the route (404, or 403route_not_mapped) falls back to theGET /api/identity/sessionsprobe: the session is known, the profile is not, and the badge is "Identity unavailable". - Every non-2xx body is flat
{code, message, details?}and becomes anIdentityError. The UI showsmessageonly; a missing or unreadable body shows "The request could not be completed." - A 429 with
Retry-After(seconds or an HTTP date) adds when to try again: "Try again in 1 minute (at 14:03)." or "Try again in 3 minutes (at 14:05)." The value is onIdentityError.retryAfterin seconds. - Every request sends
X-Requested-With: XMLHttpRequestandcredentials: 'same-origin'. The session cookie is HttpOnly; the kit never sees it. 401 invalid_loginis a credential error and stays on its form (including a wrong current password onPUT /api/password). Any other 401 means the session ended: the provider moves to the sign-in screen with the "Session expired" state.- After a failed sign-in, keyboard focus moves to the error (the
role="alert"element itself, with a focus-visible ring), so keyboard and screen-reader users land on the reason.IdentityGateclears the error on each attempt, so focus moves after every failure. An app renderingSignInScreendirectly must do the same (passerror={null}while a new attempt runs); an error left mounted across attempts takes focus only on the first failure. - A 403 on keys, pairing codes or sessions renders
SignInRequired reason="denied"with no create control. - One-time values (key, pairing code) live only in component state and are cleared on dismiss, unmount and session change. They never reach storage, URL, logs or errors.
useIdentity()exposesstatus,profile,scopes,badge(forWhoamiBadge;assuranceislocalunless the server saysverified) and the actions.
Known gaps in the server (as run against Basalisk)
- Older identity modules have no
GET /api/identity/profile(403 route_not_mapped). Against those the profile and scopes are known only after setup or sign-in; after a reloadprofileandscopesarenull, the badge is "Identity unavailable", and the Pairing page can only learn it is denied from the server's 403. - There is no scope catalogue. The scope picker offers the caller's own scopes, the host's
scopeSuggestions, and free-text entry. - Pairing codes have no list or revoke route, so that page is an explanation and one action.
- An empty key list is
{"keys":null}, and revoked keys disappear from the list. Status therefore comes fromexpires_atalone (active / expiring within 7 days / expired). - Key wording comes from
kit-account'sApiTokenManagerlabelsprop (and a failed create shows in the dialog throughcreateError), so@hollis-labs/kit-accountwith those props must be released before this package.
