Catalog npm
Back to packageRELEASE DETAILS

1.6.0

npm

@0account/web

0account web integration library

0accountauthauthenticationloginoauth2oidcsigninsignupzero-account
Published23 Aug 2026
Direct dependencies5
Transitive dependenciesNot calculated

README

Current package documentation

@0account/web

Browser-native OAuth2/OIDC authentication widget for 0account.
Drop in a <zero-account> element — it handles PKCE, QR code, SSE polling, and redirects.


Install

npm install @0account/web

Or via CDN (no build step):

<script type="module" src="https://unpkg.com/@0account/web/dist/0account-web.js"></script>

Quickstart — Widget

The widget covers the full auth flow for you. Add the element, listen for one event.

<zero-account
  app-id="YOUR_APP_ID"
  redirect-uri="https://yourapp.com/callback"
  finalize-uri="https://yourapp.com/api/auth/finalize"
  scope="openid profile email"
  with-button
></zero-account>
import "@0account/web";

document.querySelector("zero-account")
  .addEventListener("0account-authenticated", (e) => {
    // Code exchange was handled by finalize-uri — you're done.
    console.log("logged in", e.detail);
  });

Your finalize-uri backend receives { code, code_verifier, state, nonce, redirect_uri } as JSON.
Exchange the code with 0account's /oauth/token endpoint there.

Automatic redirect after login (OIDC flow)

Add mode="redirect" and the widget navigates to redirect-uri automatically:

<zero-account
  app-id="YOUR_APP_ID"
  redirect-uri="https://yourapp.com/callback"
  finalize-uri="https://yourapp.com/api/auth/finalize"
  mode="redirect"
  with-button
></zero-account>

The callback URL includes the auth code as a query param and the session token in the hash:

https://yourapp.com/callback?code=…&state=…#za_session_token=…

Attributes

AttributeRequiredDescription
app-id✅Your OAuth2 application ID
redirect-uri✅OAuth redirect URI
finalize-uriYour backend endpoint that receives the auth code and completes the exchange
scopeOAuth scopes, space-separated (default: openid profile)
moderedirect — navigate to redirect-uri automatically after login
environmentdevelopment points to staging API
themelight / dark
embeddedRender inline instead of as a modal
stateOptional OAuth state parameter
with-buttonShow a pre-built trigger button
label-*Override any UI label (e.g. label-sign-in-to)

Events

All events fire on the <zero-account> element with bubbles: true, composed: true.

EventWhenevent.detail
0account-authenticatedAuth completes{ code, state, nonce, sessionToken, redirectUri }
0account-pendingAn approval is being confirmed — typically as the user returns from the mobile app{ reason: "confirming" }
0account-errorThe login cannot continue{ reason } — see below
0account-logoutServer sends logout event{ action: "logout" }
0account-trigger-openWidget opens—
0account-trigger-closeWidget closes—

0account-error reasons

reasonMeaningSuggested handling
network_unavailableThe request never reached your backend. The user's approval is still good; only the trip failed.Offer a retry — this is not a rejected login
finalize_failedYour finalize-uri answered with a non-2xx statusTreat as a failed login
session_expiredThe session lapsed. Attach mode only (session-id set), where the widget cannot mint a replacement.Restart the OIDC flow
no_session_dataThe PKCE verifier was missing from sessionStorage — blocked storage, or already consumedRestart the login
not_configuredapp-id or redirect-uri was missing when the widget was openedFix the integration

In the default widget flow an expired session is not reported as an error: the widget quietly mints a fresh one so the user can simply tap again.

Dispatch 0account-trigger-open / 0account-trigger-close on document to open/close the widget from anywhere:

document.dispatchEvent(new Event("0account-trigger-open"));

Retrieve session data after redirect

In mode="redirect", the callback page needs the PKCE verifier to exchange the code.
Read it with ZeroAccount.getSessionData() — this clears the value from sessionStorage on first call.

import { ZeroAccount } from "@0account/web";

const params = new URLSearchParams(location.search);
const code = params.get("code");
const data = ZeroAccount.getSessionData("YOUR_APP_ID"); // { verifier, nonce }

// Exchange the code on your backend
await fetch("/api/auth/finalize", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    code,
    code_verifier: data.verifier,
    state: params.get("state"),
    nonce: data.nonce,
    redirect_uri: "https://yourapp.com/callback",
  }),
});

Cross-subdomain session handoff

When redirecting a user to a different subdomain that also has the <zero-account> widget, include the session token in the URL hash — the widget reads and clears it automatically:

window.location.href = `https://app2.yoursite.com/dashboard#za_session_token=${encodeURIComponent(sessionToken)}`;

TypeScript

All types are included. Key exports:

import {
  ZeroAccount,          // Custom Element class
  ZeroAccountEvents,    // Event name constants
} from "@0account/web";

License

MIT

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 5

Native requirements
5 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
vite
Environment
{
  "local_name": "vite",
  "alias": false,
  "peer_metadata": null
}
^6.4.1development
terser
Environment
{
  "local_name": "terser",
  "alias": false,
  "peer_metadata": null
}
^5.46.0development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
^5.9.3development
vite-plugin-dts
Environment
{
  "local_name": "vite-plugin-dts",
  "alias": false,
  "peer_metadata": null
}
^4.5.4development
@vitejs/plugin-basic-ssl
Environment
{
  "local_name": "@vitejs/plugin-basic-ssl",
  "alias": false,
  "peer_metadata": null
}
^2.1.4development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "b66e6274e7b643aa9849bd6b409828178ebfdce3",
  "tarball": "https://registry.npmjs.org/@0account/web/-/web-1.6.0.tgz",
  "fileCount": 14,
  "integrity": "sha512-S/xpVjjbj13BZGfei1eX1LF7wChO0qFWwfu2s3sLFqIs7h8osbmFzuNZuTLaCScPVrPdodp/95Zw3VZ8zlwp7A==",
  "signatures": [
    {
      "sig": "MEYCIQCZUVgHSa+7FdBbej9Qk08yLi9ut7/hgnRThllBK0hq2QIhAIyLR3itIDi7orD622aMuD+hqY7L1qo8aVqeRFHYylHF",
      "keyid": "SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"
    }
  ],
  "unpackedSize": 465056
}

Repository

PENDING
oila-gmbh/0account-web

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:04 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:31dd68f144a26bbf1c1053dc10bf7c2dcc545afbb2ef844d701ff5e452564639

Other collected versions

1.7.026 Aug1.5.123 Aug1.5.023 Aug1.4.023 Aug1.3.923 Aug1.3.823 AugView all collected versions →