Catalog npm
PACKAGE EXPLORERView in registry

@0account/web

npm

0account web integration library

0accountauthauthenticationloginoauth2oidcsigninsignupzero-account
Versions collected42
Direct dependencies5From release 1.7.0
Last observed20 Oct, 22:04 UTC

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.

Versions 42

Collected releases
VersionPublishedDirect dependenciesOpen version
1.7.0Registry latest26 Aug 20265
1.6.023 Aug 20265
1.5.123 Aug 20265
1.5.023 Aug 20265
1.4.023 Aug 20265
1.3.923 Aug 20265
1.3.823 Aug 20265
1.3.73 Aug 20265
1.3.63 Aug 20266
1.3.53 Aug 20266
1.3.413 May 20266
1.3.312 May 20266
1.3.211 May 20266
1.3.19 May 20266
1.3.028 Apr 20266
1.2.926 Apr 20266
1.2.826 Apr 20266
1.2.725 Apr 20266
1.2.619 Apr 20266
1.2.519 Apr 20266

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

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:03 UTC

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

Record identity

package:adb78903d61ad9965950e894284034f46b0111b90feed40ffb019a48d16de4c5