@apollo1213/obelisk-js
v0.1.0
Published
Official JavaScript SDK for Obelisk passkey authentication.
Maintainers
Readme
obelisk-js
Official JavaScript/TypeScript SDK for Obelisk passkey authentication. Wraps the Obelisk HTTP APIs and @simplewebauthn/browser so developers can add passwordless login with just a few lines of code.
Installation
npm install @apollo1213/obelisk-jsQuick Start
import { Obelisk } from '@apollo1213/obelisk-js';
const obelisk = new Obelisk({
apiUrl: 'https://api.obelisk.dev',
apiKey: 'OBELISK_PUBLIC_KEY'
});
await obelisk.registerPasskey('[email protected]');
const session = await obelisk.loginWithPasskey();API
new Obelisk(options)
| Option | Type | Description |
| --- | --- | --- |
| apiUrl | string | Required base URL of the Obelisk backend. |
| apiKey | string | Public API key for the current site/app. Never use private keys in the browser. |
| userResolver | () => Promise<string> | Optional async callback returning the current user ID/email for flows that require it. |
registerPasskey(email: string): Promise<void>
Starts the WebAuthn attestation ceremony for the provided user and finalizes it with the backend. Replaces any existing key for that user.
loginWithPasskey(): Promise<ObeliskSession>
Runs the authentication ceremony and returns session data from the backend.
replacePasskey(): Promise<void>
Helper that shows a friendly message and re-runs registerPasskey when the existing key is invalid.
autoLogin(): Promise<ObeliskSession | null>
Attempts loginWithPasskey. If it fails for recoverable reasons it calls replacePasskey. Returns null if manual intervention is required.
Error Handling
Every API throws subclasses of ObeliskError with descriptive messages. Network issues throw NetworkError, WebAuthn issues throw CredentialMissingError or ChallengeError depending on context.
Building
npm install
npm run buildLicense
MIT
