JavaScript SDK

Client setup

Create a ScuteClient, its options and defaults, where it keeps the session, and what it does on start.

ScuteClient is the object every call goes through. createClient(config) and new ScuteClient(config) are the same.

import { createClient } from "@scute/js-core";const scute = createClient({ appId: process.env.SCUTE_APP_ID });

Options#

appIdstring | numberrequired
The app's ID. The constructor throws ScuteError("Scute appId is required!") without it.
baseUrlstring
API base URL. Default https://api.scute.io.
secretKeystring
The app's secret key, for scute.admin calls. Server only: in a browser it is ignored, a warning is logged and it is never sent.
clientIpstring | null
The signing-in person's IP address, for a client made per request on your server. Sent as X-Scute-Client-IP on calls made with the secret key. One IPv4 or IPv6 address; a list or a range throws. See Admin API.
preferencesScuteClientPreferences
Session behavior. See below.
onBeforeInitialize(this: ScuteClient) => void
Runs inside the constructor before the first request.
debugboolean
Log each step with console.debug. Default false.
errorReportingboolean
Send client-side errors (not HTTP errors under 500) to Scute from the browser. Default false. Reported URLs have sct_magic, sct_oauth and sct_sk removed.

Preferences#

persistSessionboolean
Keep the session across page loads. Default true. false keeps it in memory for this client only.
sessionStorageAdapterScuteStorage
Where tokens are kept. Default: localStorage in a browser, memory elsewhere.
autoRefreshTokenboolean
Refresh the access token before it expires. Default true. The app's own auto_refresh setting can turn it off, never on.
refetchOnWindowFocusboolean
Check the session again when the tab becomes visible. Default true.
refetchInvervalnumber
Seconds between session checks in the background. Default 300. The option name is spelled refetchInverval in the SDK.
fingerprintingboolean
Load a device fingerprint in the browser and send it as X-Fingerprint on every request that is not a GET. Default true. A request sent while it loads waits up to 2 seconds for it.

What the client does on start#

The constructor fetches the app's settings (getAppData()), which decide the sign-in method, whether passkeys are on, and auto refresh. In a browser it also opens a BroadcastChannel for cross-tab sync, starts the background refresh and listens for tab visibility.

A failed settings load is not cached: the next call tries again. signIn and signInOrUp return that error instead of guessing a method.

const { data: app, error } = await scute.getAppData();// app.email_auth_type: "magic" | "otp"// app.passkeys_enabled, app.allowed_identifiers, app.oauth_providers, ...const fresh = await scute.getAppData(true); // skip the cached copy

Storage#

Every key the client writes is suffixed with __ and the app ID, so two Scute apps on one origin keep separate sessions.

KeyHolds
sc-access-token__<appId>The access token
sc-refresh-token__<appId>The refresh token
sct_last_login__<appId>The last identifier used to sign in
sct_cred_data__<appId>Passkey credential IDs registered on this device

A storage adapter is any object with getItem(key), setItem(key, value) and removeItem(key), sync or async. For cookies, extend ScuteCookieStorage, or use ScuteBrowserCookieStorage (cookies set with js-cookie):

import { createClient, ScuteBrowserCookieStorage } from "@scute/js-core";const scute = createClient({  appId: "YOUR_APP_ID",  preferences: {    sessionStorageAdapter: new ScuteBrowserCookieStorage({ sameSite: "lax" }),  },});

Cookies are Secure by default, except on plain http://localhost pages. The default path is /.

Sandbox#

scute.isSandbox is true once a response carried X-Scute-Sandbox: true. scute.environment is "production" or "sandbox".

One client per app#

Create the client once and share it. A second ScuteClient for the same app ID in one browser logs a warning; clients for different app IDs coexist.

The client also holds:

PropertyTypePage
scute.adminScuteAdminApiAdmin API
scute.authzScuteAuthzApiPermission checks
scute.verificationsScuteVerifyApiVerifications inbox
scute.appId, scute.baseUrlstring