Documentation menu

Guides

Offline mode

Let activated devices keep working without an internet connection for a period you choose.

How it works

While online, your app requests an offline lease: a signed note saying “this device may use this license until a certain time”. Your app saves it, and while there's no connection it checks the saved lease instead of calling Atlas.

  1. Turn on Offline access in the policy and choose the maximum lease length (for example 14 days).
  2. After activating, request a lease and save it.
  3. Request a fresh lease whenever the app is online, well before the old one expires.
  4. When offline, verify the saved lease and use its entitlements.

Request and verify a lease

ts
import { verifyOfflineLease } from "@atlas/sdk";

// Online: get a lease and save the whole response.
const lease = await atlas.lease({
  license_key: storedKey,
  product_id: PRODUCT_ID,
  device: { id: machineId },
});
await storage.save("lease", JSON.stringify(lease));

// Offline: check the saved lease before unlocking.
const check = await verifyOfflineLease(JSON.parse(await storage.load("lease")), {
  publicKey: BUNDLED_PUBLIC_KEY, // from atlas.signingKey(), bundled with your app
  deviceId: machineId,
  productId: PRODUCT_ID,
});

if (check.valid) enableFeatures(check.lease.entitlements);
else showMessage("Connect to the internet to keep using the app.");

verifyOfflineLease checks the signature, the expiry, and that the lease belongs to this device and product. Save the full response, not just data, or the signature can't be checked.

How long a lease lasts

A lease never outlives the license. Atlas uses the shortest of: the length you ask for (ttl_seconds, optional), the policy's maximum, and the time left before the license expires plus its grace period.

Pick a length you're comfortable with

If you suspend or revoke a license, an offline device keeps working until its lease runs out. Shorter leases mean changes reach customers sooner; longer leases suit customers who are often offline.

When a lease is refused

A lease request fails if the device isn't activated (not_activated), the license doesn't allow offline use (offline_not_allowed), or the license is no longer active. Keep using the previous lease until it expires, then ask the user to go online.