Skip to navigation

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

SupportedRecommended
Node.js16.9 and newerThe current LTS release
ModulesES modules (import)
PackagesNone
WindowsAny Windows that runs your Node.js version

On Linux and macOS, pass your own systemId and storage when you create the client.

Add the SDK to your project

npm install authlyx@beta
import { AuthlyX, AuthlyXError } from "authlyx";

If you copied AuthlyX.js into your project instead, import it by path:

import { AuthlyX, AuthlyXError } from "./AuthlyX.js";

The SDK uses import, so your project needs "type": "module" in package.json, or your file must end in .mjs.

Create the client

const app = new AuthlyX("YOUR_APP_KEY", "1.0.0");

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:

export const app = new AuthlyX("YOUR_APP_KEY", "1.0.0");

Creating the client does not connect. Nothing is sent until you call init. Optional settings go in a third object:

const app = new AuthlyX("YOUR_APP_KEY", "1.0.0", { updatePrompt: false, requestTimeout: 15000 });

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.

StyleLooks likeA refused call
awaitconst result = await app.init();Throws AuthlyXError
Callbackapp.init(result => { ... });Arrives as a result with ok set to false

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.

const started = await app.init();
if (!started.ok) {
console.log(started.message);
process.exit(1);
}
app.init(started => {
console.log(started.ok ? "Connected" : started.message);
});

init resolves with a result even when something is wrong, instead of throwing:

CodeokWhat happened
APP_INITIALIZEDtrueConnected. Continue to sign-in.
OFFLINE_MODEtrueNo internet, but this PC has saved offline access. See Offline access.
NETWORK_...falseNo internet and nothing saved. Ask the user to try again.
UPDATE_REQUIREDfalseThis version is older than the one in your dashboard. The SDK has already shown an update box.
VERSION_MISMATCHfalseThis version is newer than the dashboard version and is not allowed.
APP_DISABLEDfalseYou paused the app in the dashboard.

Sign in

await app.login("YOUR_LICENSE_KEY");
await app.login("YOUR_USERNAME", "YOUR_PASSWORD");
await app.deviceLogin();

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:

try {
await app.login(licenseKey);
console.log("Welcome");
} catch (error) {
console.log(error.message);
}

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:

error.kindMeaningWhat to do
serverAuthlyX answered and said noShow the message
networkNo answer: no internet, firewall, timeoutAsk the user to retry. Do not treat it as a ban.
securityA reply failed verificationDo not unlock anything
storageThe SDK could not read or save its protected filesUsually a permissions problem
cancelledThe request was cancelled or the client was closedNothing

All codes are on the Errors page.

With a callback, no try is needed:

app.login(licenseKey, result => {
console.log(result.ok ? "Welcome" : result.message);
});
app.login(username, password, result => {
console.log(result.ok ? "Welcome" : result.message);
});

A sign-in function you can reuse:

async function signIn(licenseKey) {
try {
await app.login(licenseKey);
return { ok: true, error: "" };
} catch (error) {
return { ok: false, error: error.message };
}
}

Create an account, change the password, add time

await app.registerUser("YOUR_USERNAME", "YOUR_PASSWORD", "YOUR_LICENSE_KEY");
await app.changePassword("CURRENT_PASSWORD", "NEW_PASSWORD");
await app.redeemLicense("ANOTHER_LICENSE_KEY");

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:

const user = app.userData;
console.log(user.Username, user.Plan, user.ExpiryDate);
FieldExampleNotes
UsernamemayaOnly set for username and password accounts
LicenseKeyMAYA-4R8P-2N6K-9Q3WThe key used to sign in or linked to the account
Emailmaya@example.com
PlanPlus
ExpiryDate2027-04-30T23:59:59.000Znull for lifetime access
SIDS-1-5-21-...The Windows user ID this sign-in is bound to
DeviceLimit3
Country, IpAddressNGWhere the sign-in came from
typelicenseuser, license or device
registeredAt, lastLogin2026-08-12T14:22:10.000Z
features["aim", "esp"]Enabled on/off features
featureValues, metadata{ fov: 90 }See Features and metadata

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

function expiryText() {
const expiry = app.userData.ExpiryDate;
return expiry ? expiry.slice(0, 10).replaceAll("-", "/") : "Lifetime";
}
function daysLeft() {
const expiry = app.userData.ExpiryDate;
if (!expiry) return 0;
return Math.max(0, Math.ceil((Date.parse(expiry) - Date.now()) / 86400000));
}
function buildTopLine() {
const user = app.userData;
if (!user.LicenseKey) return " License: Null";
return ` License: ${user.LicenseKey} | Expiry: ${expiryText()}`;
}
function remainingDays() {
const user = app.userData;
if (!user.Plan) return "N/A";
if (!user.ExpiryDate) return "Lifetime";
return `${daysLeft()}D`;
}
function isPremium() {
return app.userData.Plan === "Premium";
}

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:

const user = app.userData;
const aim = (user.features ?? []).includes("aim");
const quality = user.featureValues?.quality ?? "low";
const discord = user.metadata?.discord ?? "";

The values refresh on every heartbeat, so dashboard changes show up without signing in again. Helpers for text, numbers and yes/no values:

function feature(name, fallback = "") {
const value = app.userData.featureValues?.[name];
return value === undefined || value === null ? fallback : String(value);
}
function featureInt(name, fallback = 0) {
const number = Number(feature(name, ""));
return feature(name, "") !== "" && Number.isFinite(number) ? Math.trunc(number) : fallback;
}
function featureBool(name, fallback = false) {
const text = feature(name).toLowerCase();
if (["true", "1", "yes", "on"].includes(text)) return true;
if (["false", "0", "no", "off"].includes(text)) return false;
return fallback;
}
const fov = featureInt("fov", 90);
const rainbow = featureBool("rainbow");

Copy the same three functions with metadata in place of featureValues for metadata.

Ask AuthlyX directly

const everything = await app.getFeatures();
console.log(everything.data.features);
const quality = await app.getFeature("quality");
console.log(quality.data.value);
const aim = await app.checkFeature("aim");
console.log(aim.data.enabled);
const allMeta = await app.getAllMetadata();
const discord = await app.getMetadataValue("discord");
const vip = await app.checkMetadata("vip");
console.log(allMeta.data.metadata, discord.data.value, vip.data.enabled);

In JavaScript, getMetadata() returns all metadata and getMetadataValue(key) returns one key.

Save metadata

await app.setMetadata("discord", "maya#1234");
await app.setMetadata("level", 5);
await app.setMetadata("vip", true);

Only keys you allowed for SDK writes in the dashboard can be changed.

Cloud variables

const motd = await app.getVariable("motd");
console.log(motd.data);
app.getVariable("motd", result => {
if (result.ok) console.log(result.data);
});
await app.updateVariable("last_build", "1.4.2");

For getVariable, data is the value itself. See Cloud variables.

Scripts

const script = await app.getScript("startup");
console.log(script.data.content);

The SDK checks the script’s signature before returning it. It does not run the script. See Scripts.

Logs and webhooks

await app.log("Opened the settings page");
await app.sendWebhook("purchase.clicked", { item: "skin_42", price: 4.99 });

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.

if (!(await app.hasAccess())) {
showLoginScreen();
}

To be told when the session ends, pass functions when you create the client:

const app = new AuthlyX("YOUR_APP_KEY", "1.0.0", {
onSessionInvalidated: error => {
console.log("Signed out:", error.message);
process.exit(0);
},
onConnection: state => console.log("Connection:", state),
});

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

await app.login(licenseKey);
await app.saveOfflineAccess();

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:

const started = await app.init();
if (started.code === "UPDATE_REQUIRED" || started.code === "VERSION_MISMATCH") {
const update = started.data?.update ?? {};
console.log(started.message, update.version, update.url, update.notes);
}

See Automatic updates.

Sign out and shut down

await app.logout();
await app.close();

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:

const started = await app.init(AbortSignal.timeout(5000));

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

Result memberMeaning
ok / successTrue when the call worked
failedThe opposite of ok
codeFixed code such as APP_INITIALIZED or LICENSE_EXPIRED
messageText you can show to the user
requestIdQuote this when you contact support
dataThe call’s data

AuthlyXError has message, code, kind, status, requestId and data.

Options

OptionDefaultWhat it does
updatePrompttrueShow the built-in update boxes
requestTimeout8000Milliseconds one call may take, including retries
retryLimit2How many times a failed request is retried (0 to 5)
heartbeat"server""manual" to run session checks yourself
onSessionInvalidatedNoneCalled when AuthlyX ends the session
onConnectionNoneCalled when the connection state changes
buildHash""This build’s hash, if you use Application hashes
storageProtected files in %LOCALAPPDATA%\AuthlyX\v3Another store, such as new WindowsProtectedStore(path)
systemIdThe Windows user SIDRequired on Linux and macOS

A complete program

import { createInterface } from "node:readline/promises";
import { AuthlyX } from "authlyx";
const app = new AuthlyX("YOUR_APP_KEY", "1.0.0");
const input = createInterface({ input: process.stdin, output: process.stdout });
const started = await app.init();
if (!started.ok) {
console.log(started.message);
process.exit(1);
}
const licenseKey = await input.question("License key: ");
try {
await app.login(licenseKey);
} catch (error) {
console.log(error.message);
process.exit(1);
}
const user = app.userData;
console.log("Plan:", user.Plan);
console.log("Expires:", user.ExpiryDate ?? "Lifetime");
if ((user.features ?? []).includes("beta")) console.log("Beta features are on");
await input.question("Press Enter to sign out");
await app.logout().catch(() => {});
await app.close();
input.close();

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.