Registry / auth-security / onz-auth

onz-auth

JSON →
library1.0.26jsnpmunverified

OnzAuth JavaScript SDK v1.0.26 (latest) for passwordless authentication using Email Magic Link and WebAuthN. It provides a simple popup or iframe-based login flow with automatic token storage in localStorage (access_token, id_token, refresh_token, expiry). The SDK is ESM-only (no CommonJS support) and requires a client ID from OnzAuth. It emits events ('authenticated', 'error', 'closed') and is designed for quick integration. Key differentiators: no callback URLs to configure, built-in WebAuthN support, and no password management. It is a client-side only library with a small API surface, released irregularly with bug fixes.

npm install onz-auth
INSTALL
IMPORT
SIG · ONZ-AUTH
O
onz-auth
auth-securityjavascriptv1.0.26
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Auth
import onz from 'onz-auth'; const auth = new onz.Auth({ clientID: '...' });
const { Auth } = require('onz-auth'); const auth = new Auth({ clientID: '...' });
The default import is the module itself. Access the Auth class as onz.Auth. CommonJS require is not supported.
Auth (named import)
import onz from 'onz-auth'; const auth = new onz.Auth({ clientID: '...' });
import { Auth } from 'onz-auth';
There is no named export 'Auth'. You must use the default import and access Auth via onz.Auth.
UMD script tag
<script src="https://unpkg.com/onz-auth@1.0.26/dist/onz-auth-js-sdk.min.js"></script>
<script src="https://unpkg.com/onz-auth/dist/onz-auth-js-sdk.min.js"></script>
Always pin a version to avoid breaking changes. The global variable is 'onz'.
Event 'authenticated'
auth.on('authenticated', (result) => { console.log(result.accessToken); });
auth.on('authenticated', function(result) { console.log(result.accessToken); });
The event emits an object with camelCase keys: accessToken, idToken, refreshToken, expiry.

Initializes OnzAuth, listens for authentication events, triggers a login popup, and logs the tokens. Also demonstrates error handling and logout.

import onz from 'onz-auth'; const auth = new onz.Auth({ clientID: process.env.ONZAUTH_CLIENT_ID ?? 'your-client-id', containerID: 'auth-container', isIframe: false }); auth.on('authenticated', (authResult) => { console.log('Access Token:', authResult.accessToken); console.log('ID Token:', authResult.idToken); console.log('Refresh Token:', authResult.refreshToken); console.log('Expiry:', authResult.expiry); }); auth.on('error', (errorMessage) => { console.error('Auth error:', errorMessage); }); auth.on('closed', () => { console.log('Login window closed'); }); // Show login popup auth.showLogin(); // Later, to logout: auth.logout();
Debug
Known issues
gotchaTokens are stored automatically in localStorage with keys: access_token, id_token, expiry, refresh_token. Do not manually manage them.
fix
Use the 'authenticated' event to get tokens; avoid reading from localStorage directly.
affects: >=1.0.0
gotchaThe library uses popup windows or iframes. Ensure your site allows popups (not blocked by the browser).
fix
Set isIframe: true to use an iframe instead, which requires a container element.
affects: >=1.0.0
gotchaWebAuthN is disabled by default. It must be enabled in the OnzAuth project settings.
fix
Log in to OnzAuth dashboard > project settings > enable WebAuthN.
affects: >=1.0.0
breakingNo CommonJS support. Using require() will fail with: "ERR_REQUIRE_ESM"
fix
Use import statements or switch to the UMD script tag for non-module environments.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: onz.Auth is not a constructor
Using named import `import { Auth } from 'onz-auth'` which is not exported as a named member.
fix
Use default import: `import onz from 'onz-auth';` then `new onz.Auth(...)`.
Cannot read properties of undefined (reading 'accessToken')
Accessing tokens before the 'authenticated' event fires, or using wrong key casing.
fix
Listen to the 'authenticated' event and use `authResult.accessToken` (camelCase).
Error: Client ID is required
Instantiated Auth without a clientID option.
fix
Provide clientID: 'your-client-id' in the Auth constructor options.
Failed to load resource: net::ERR_BLOCKED_BY_CLIENT
Browser blocked the popup window.
fix
Set isIframe: true to use an iframe, or allow popups for your site.
Upgrade
Version history
1.0.26latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
onz-auth — npm install onz-auth · libregistry