JavaScript guide
This page walks through the whole JavaScript SDK in the order you would use it. Each step starts with the shortest code that works, then shows the other ways to write it. The SDK runs in Node.js and in Electron’s main process. It does not run in a browser page.
Download the JavaScript SDK or install it from npm if you have not done so yet. Using TypeScript? See the TypeScript guide.
Requirements
On Linux and macOS, pass your own systemId and storage when you create the client.
Add the SDK to your project
If you copied AuthlyX.js into your project instead, import it by path:
The SDK uses import, so your project needs "type": "module" in package.json, or your file must end in .mjs.
Create the client
The first value is your app’s AppKey. Find it in the dashboard under your application’s credentials. The second is the version of the program you are building. AuthlyX compares it with the versions you allow in the dashboard, so raise it each time you ship a new build. See Allowed Versions.
Create one client for the whole program and export it from a module if several files need it:
Creating the client does not connect. Nothing is sent until you call init. Optional settings go in a third object:
All of them are listed in Options.
Two ways to call the SDK
Every call that talks to AuthlyX returns a promise. You can await it, or pass a callback.
Neither blocks Node.js, so both are fine in Electron and in servers. Callbacks exist for init, initialize, login, registerUser, changePassword, redeemLicense, log, getVariable, updateVariable, getScript, getFeatures, getFeature, getAllMetadata, getMetadata, getMetadataValue, checkMetadata and sendWebhook. The others are await only.
Start the SDK
Call init once, before signing in. initialize is the same method with a longer name.
init resolves with a result even when something is wrong, instead of throwing:
Sign in
One value is a license key, two values are a username and password, and deviceLogin signs in the current Windows user with no form. Device login only works for devices you approved first; see Device login.
With await, a refused sign-in throws:
error.message is ready to show to the user. When the error comes from the SDK it is an AuthlyXError, and error.code is a fixed code for your own checks, such as INVALID_CREDENTIALS, LICENSE_NOT_FOUND, LICENSE_EXPIRED, LICENSE_BANNED, DEVICE_NOT_ALLOWED or DEVICE_LIMIT_REACHED. error.kind says what sort of problem it was:
All codes are on the Errors page.
With a callback, no try is needed:
A sign-in function you can reuse:
Create an account, change the password, add time
registerUser creates a user account and signs it in. The other two need a signed-in user. Each also takes a callback as its last value.
Read the account
After sign-in, app.userData holds the account details:
Before sign-in and after sign-out, app.userData is an empty object, so every field is undefined.
Functions that return text, numbers and yes/no
daysLeft() rounds up, so one hour left counts as 1 day.
Features and metadata
Features come from the plan and the account. Some are on/off, some carry a value such as "high" or 90. Metadata is extra information attached to accounts. See Features and metadata.
Read them from the account
These do not contact AuthlyX:
The values refresh on every heartbeat, so dashboard changes show up without signing in again. Helpers for text, numbers and yes/no values:
Copy the same three functions with metadata in place of featureValues for metadata.
Ask AuthlyX directly
In JavaScript, getMetadata() returns all metadata and getMetadataValue(key) returns one key.
Save metadata
Only keys you allowed for SDK writes in the dashboard can be changed.
Cloud variables
For getVariable, data is the value itself. See Cloud variables.
Scripts
The SDK checks the script’s signature before returning it. It does not run the script. See Scripts.
Logs and webhooks
log writes a line to your app’s logs in the dashboard. sendWebhook sends an event to a webhook you set up in the dashboard; the second value is any JSON-compatible object.
Staying signed in
After sign-in the SDK checks in with AuthlyX in the background (a heartbeat), by default about every 10 minutes, and refreshes features and metadata each time. If you ban, pause or expire the account, the next heartbeat ends the session.
To be told when the session ends, pass functions when you create the client:
onConnection receives online, disconnected, untrusted or disposed. To check right away, call await app.checkSession(); await app.onResume() does the same and is meant for when your app wakes from sleep. To run the heartbeat yourself, pass heartbeat: "manual" and call checkSession() from your own timer. More in Sessions and heartbeats.
Offline access
Later, without internet, init returns OFFLINE_MODE with ok true, and the user signs in with the same license key or username and password. The SDK checks them against the saved permit and the sign-in succeeds with the code OFFLINE_ACCESS. await app.hasOfflineAccess() tells you whether this PC has a valid saved permit. Signing out deletes it. See Offline access.
Updates
When this version is not allowed, init fails with UPDATE_REQUIRED or VERSION_MISMATCH and the SDK shows a message box with the new version, release notes and a button to open your download page. To show your own screen, pass updatePrompt: false and read the details:
See Automatic updates.
Sign out and shut down
logout ends the session, clears userData and deletes saved offline access on this PC. close stops the background heartbeat and releases the client; call it when your program is done with AuthlyX. A closed client cannot be used again.
Cancel a call
Calls that take a signal accept an AbortSignal in place of the callback:
AbortSignal.timeout needs Node.js 17.3 or newer; on 16.9 use an AbortController and call abort() yourself. A cancelled call throws an AuthlyXError with kind set to cancelled.
Results and errors
AuthlyXError has message, code, kind, status, requestId and data.
Options
A complete program
node:readline/promises needs Node.js 17 or newer. Each method also has its own page with every language side by side under SDK methods.

