{"id":28009,"library":"onz-auth","title":"OnzAuth JavaScript SDK","description":"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.","status":"active","version":"1.0.26","language":"javascript","source_language":"en","source_url":"https://github.com/zailky/onz-auth-js","tags":["javascript","login","signin","authentication","authorisation","signup","openid","auth","jwt"],"install":[{"cmd":"npm install onz-auth","lang":"bash","label":"npm"},{"cmd":"yarn add onz-auth","lang":"bash","label":"yarn"},{"cmd":"pnpm add onz-auth","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The default import is the module itself. Access the Auth class as onz.Auth. CommonJS require is not supported.","wrong":"const { Auth } = require('onz-auth'); const auth = new Auth({ clientID: '...' });","symbol":"Auth","correct":"import onz from 'onz-auth'; const auth = new onz.Auth({ clientID: '...' });"},{"note":"There is no named export 'Auth'. You must use the default import and access Auth via onz.Auth.","wrong":"import { Auth } from 'onz-auth';","symbol":"Auth (named import)","correct":"import onz from 'onz-auth'; const auth = new onz.Auth({ clientID: '...' });"},{"note":"Always pin a version to avoid breaking changes. The global variable is 'onz'.","wrong":"<script src=\"https://unpkg.com/onz-auth/dist/onz-auth-js-sdk.min.js\"></script>","symbol":"UMD script tag","correct":"<script src=\"https://unpkg.com/onz-auth@1.0.26/dist/onz-auth-js-sdk.min.js\"></script>"},{"note":"The event emits an object with camelCase keys: accessToken, idToken, refreshToken, expiry.","wrong":"auth.on('authenticated', function(result) { console.log(result.accessToken); });","symbol":"Event 'authenticated'","correct":"auth.on('authenticated', (result) => { console.log(result.accessToken); });"}],"quickstart":{"code":"import onz from 'onz-auth';\n\nconst auth = new onz.Auth({\n  clientID: process.env.ONZAUTH_CLIENT_ID ?? 'your-client-id',\n  containerID: 'auth-container',\n  isIframe: false\n});\n\nauth.on('authenticated', (authResult) => {\n  console.log('Access Token:', authResult.accessToken);\n  console.log('ID Token:', authResult.idToken);\n  console.log('Refresh Token:', authResult.refreshToken);\n  console.log('Expiry:', authResult.expiry);\n});\n\nauth.on('error', (errorMessage) => {\n  console.error('Auth error:', errorMessage);\n});\n\nauth.on('closed', () => {\n  console.log('Login window closed');\n});\n\n// Show login popup\nauth.showLogin();\n\n// Later, to logout:\nauth.logout();","lang":"javascript","description":"Initializes OnzAuth, listens for authentication events, triggers a login popup, and logs the tokens. Also demonstrates error handling and logout."},"warnings":[{"fix":"Use the 'authenticated' event to get tokens; avoid reading from localStorage directly.","message":"Tokens are stored automatically in localStorage with keys: access_token, id_token, expiry, refresh_token. Do not manually manage them.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set isIframe: true to use an iframe instead, which requires a container element.","message":"The library uses popup windows or iframes. Ensure your site allows popups (not blocked by the browser).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Log in to OnzAuth dashboard > project settings > enable WebAuthN.","message":"WebAuthN is disabled by default. It must be enabled in the OnzAuth project settings.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use import statements or switch to the UMD script tag for non-module environments.","message":"No CommonJS support. Using require() will fail with: \"ERR_REQUIRE_ESM\"","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'access':35 'api':97 'auth':111 'authent':11,61,107 'authoris':108 'automat':30 'base':26 'bug':102 'built':78 'built-in':77 'callback':73 'client':54,90 'client-sid':89 'close':63 'commonj':49 'configur':76 'design':66 'differenti':71 'email':13 'emit':59 'error':62 'esm':46 'esm-on':45 'event':60 'expiri':41 'fix':103 'flow':28 'id':37,55 'ifram':25 'iframe-bas':24 'integr':69 'irregular':100 'javascript':2,5,104 'jwt':112 'key':70 'latest':8 'librari':93 'link':15 'localstorag':34 'login':27,105 'magic':14 'manag':85 'onzauth':1,4,57 'openid':110 'password':84 'passwordless':10 'popup':22 'provid':19 'quick':68 'refresh':39 'releas':99 'requir':52 'sdk':3,6,43 'side':91 'signin':106 'signup':109 'simpl':21 'small':96 'storag':32 'support':50,81 'surfac':98 'token':31,36,38,40 'url':74 'use':12 'v1.0.26':7 'webauthn':17,80","created_at":"2026-05-09T05:53:15.359008+00:00","updated_at":"2026-05-09T05:53:15.359008+00:00","problems":[{"fix":"Use default import: `import onz from 'onz-auth';` then `new onz.Auth(...)`.","cause":"Using named import `import { Auth } from 'onz-auth'` which is not exported as a named member.","error":"TypeError: onz.Auth is not a constructor"},{"fix":"Listen to the 'authenticated' event and use `authResult.accessToken` (camelCase).","cause":"Accessing tokens before the 'authenticated' event fires, or using wrong key casing.","error":"Cannot read properties of undefined (reading 'accessToken')"},{"fix":"Provide clientID: 'your-client-id' in the Auth constructor options.","cause":"Instantiated Auth without a clientID option.","error":"Error: Client ID is required"},{"fix":"Set isIframe: true to use an iframe, or allow popups for your site.","cause":"Browser blocked the popup window.","error":"Failed to load resource: net::ERR_BLOCKED_BY_CLIENT"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":"https://www.onzauth.com","github":"https://github.com/zailky/onz-auth-js","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/onz-auth","openapi_spec":null,"status_page":null,"smithery":null,"categories":["auth-security","web-framework"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-05-09","next_check":"2026-08-07","install_tag":null}}