DecaneDocs
Sign-inServer-side sign-in
Sign-in

Server-side sign-in

Since v1.2.0 decane-node can also authenticate users — the same flows the frontend SDKs run, minus anything that needs a browser or a device authenticator. Every successful sign-in resolves to a DecaneAuthResult:

ts
interface DecaneAuthResult {
  accessToken: string;   // Decane JWT (~30 min, no refresh token)
  userId: string;        // stable Decane user id
  isNewUser: boolean;
  hasShare: boolean;     // false = no wallet yet (creation is client-side)
  profile?: { name?: string; email?: string; picture?: string };
}

Verify the token with verifyAccessToken(result.accessToken), resolve addresses with getUser(result.accessToken), or hand it to the end user’s client. Not available server-side (they need a browser or an authenticator): the Google redirect flow, the interactive KingsChat popup, passkey sign-in, and wallet creation/signing.

The API key

Sign-in calls are authenticated by your developer API key (dck_live_…, from the Decane dashboard), sent as X-API-Key. Pass it as apiKey or set the DECANE_API_KEY env var. Verification and address resolution never need it — a key-less client keeps working, and only throws if you call a sign-in method.

ts
const decane = new DecaneClient({
  appId: process.env.DECANE_APP_ID,
  apiKey: process.env.DECANE_API_KEY, // dck_live_…
});
!

The dck_live_… key is a secret. In the browser SDKs it is protected by an origin allowlist; a server request carries no Origin header, so the key alone is the credential. Keep it in server env only — never ship it to a client.

Email OTP

ts
await decane.connectWithEmail("user@example.com"); // emails a 6-digit code

// …user reads the code out of their inbox…
const session = await decane.verifyEmailCode("user@example.com", "123456");
session.accessToken; // verify it, or hand it to the client
const user = await decane.getUser(session.accessToken);

Codes live 10 minutes, at most 3 per hour per address. connectWithEmail always resolves whether or not the address is known — anti-enumeration by design, so never surface “email not found”. A wrong code rejects with DecaneApiError code INVALID_CODE.

Google (ID-token exchange)

ts
// Your app already obtained a Google ID token (native Sign-In, One Tap, …)
const session = await decane.connectWithGoogleToken(googleIdToken);
session.profile; // { name?, email?, picture? } — passed through, never stored

The ID token’s aud must be the Google client id configured for Decane. The exchange resolves to the same wallet as the browser redirect flow. The redirect flow itself (consent screen, callback) is browser-only.

KingsChat (access-token exchange)

ts
const { clientId, authorizationUrl } = await decane.getKingsChatConfig();
// …your app runs the OAuth dance and obtains an access token…
const session = await decane.connectWithKingsChatToken(kcAccessToken);

Rejects with code KINGSCHAT_UNAVAILABLE (HTTP 503) when the KingsChat upstream is unreachable — deliberately distinct from a bad token (AUTH_FAILED, 401).

Custom auth — connectWithToken

The cleanest server path: exchange a JWT from your own issuer (Auth0, Clerk, Firebase, or your own backend — registered as an auth provider in the Decane dashboard with its issuer and JWKS URL) for a Decane session.

ts
const session = await decane.connectWithToken(jwtFromYourIssuer);
// Pass providerId when the project has more than one enabled provider:
await decane.connectWithToken(jwt, { providerId: "prov-1" });

Error codes: INVALID_TOKEN (rejected), NO_PROVIDER, AMBIGUOUS_PROVIDER (more than one enabled, none named), and MISSING_CLAIM (the configured identity claim is absent).

Sign-out — revokeAccessToken

ts
await decane.revokeAccessToken(session.accessToken);

Adds the token to the revocation list, which backend calls like getAddresses honour immediately. Stateless verifyAccessToken still accepts it until expiry — inherent to offline verification (see Statelessness & revocation). This is the one auth call that needs no API key — just the bearer token.

Sign-in errors — DecaneApiError

Backend API failures throw DecaneApiError — distinct from verification’s DecaneAuthError — carrying the backend’s code and the HTTP status:

ts
import { DecaneApiError } from "decane-node";

try {
  await decane.verifyEmailCode(email, code);
} catch (err) {
  if (err instanceof DecaneApiError) {
    err.code;   // "INVALID_CODE", "AUTH_FAILED", "RATE_LIMITED", …
    err.status; // HTTP status; 0 when the request never completed
  }
}

Synthesised codes: a bare HTTP 429 becomes RATE_LIMITED, an unparseable error body UNKNOWN, and a failed fetch NETWORK_ERROR with status: 0.

Operational limits

  • Rate limit: the backend allows 20 requests / 15 minutes per IP across all auth endpoints. A server funnels every user through one egress IP — fine for moderate traffic and machine flows, wrong for proxying high-volume interactive login through a single box.
  • No refresh token. Access tokens expire after ~30 minutes; re-authenticating is the only renewal.
  • hasShare: false means no wallet yet. Wallet creation needs device-held key material and happens in the client SDKs; getAddresses returns all-null for such users until a client creates the wallet.