Skip to main content
Make one client for the app’s installation. The Vite starter reads the URL from VITE_BIJECTION_URL:
apps/main/src/client.ts
Browsers can read their bundled environment variables, so put only public configuration there, such as the installation URL.

Sign people in

connect(url, { contract: "discover", token }) takes an auth adapter. The client asks it for the current token on every call and every live connection, and reconnects when the adapter reports a sign-in, a sign-out or a switch. The adapters are on @bijectionhq/bijection/client:
apps/main/src/auth.ts
Feed the adapter its provider’s state with useClientAuth inside the provider. Render the caller-specific subtree once the hook returns true.
apps/main/src/App.tsx
The adapter waits while the provider restores its session, and answers no token when nobody is signed in: the client then calls as the signed-out principal, which holds only the role.anyone class grant. bijectionAuth() signs HTTP calls and watches with the browser’s session key. Pass its token adapter and HTTP proof signer to connect.

Use a local development principal

Run bijection dev --as person:alice and open the loopback app URL it prints. The browser and CLI calls with --as person:alice use the same person id in that installation. In a test installation, k.as("person:alice") acts as the same person, and person:alice is the id to use for grants.
The app server supplies a short-lived token for its own local installation. Plain bijection dev selects person:developer. Production uses the configured auth adapter.

Servers, scripts and other providers

A server or a script can pass a fixed token or an async callback that renews the token within one authorization scope. Make one client per identity. For another provider, implement ClientAuth. Have token({ refresh }) return the current token or return null after sign-out. Reject the request if a signed-in credential is unavailable. Use subscribe(changed) to notify the client synchronously when the principal, session, or audience changes.

Accept pending invitations

acceptPendingInvitations(auth, accept, onError) runs accept each time a person signs in, for an app that mounts the members library:
The callback queues contact discovery for the signed-in person. Read a returned receipt with team.acceptance to follow the lookup and its redemptions. The helper returns a cleanup function.