Browse documentation

Documentation

Connection lifecycle and status

Interpret connection states and recover through refresh, reconnect, and disconnect flows.

Read effective state before offering a tool or deciding whether a user must reconnect.

Prerequisites

Bind the external user from your authenticated server session and install @authlane/sdk.

Implement the workflow

TypeScript
import { Authlane } from '@authlane/sdk';

const authlane = new Authlane({ apiKey: process.env.AUTHLANE_API_KEY! });

export async function connectionStates(currentUser: { id: string }) {
  const user = authlane.user(currentUser.id);
  const { data, error } = await user.connections.list();
  if (error) return { data: null, error };
  return { data, error: null };
}
StateMeaningApplication action
pendingAuthorization started but has not completed.Poll briefly or keep the connect UI open.
connectedUsable credentials are stored.Enable tools for this service.
expiredThe effective access expiry has passed.Reconnect if automatic refresh cannot recover it.
errorOAuth exchange or refresh needs attention.Show a reconnect action and retain the safe error code.
disconnectedComputed when no stored connection exists.Offer a new connect session.

Authlane refreshes eligible OAuth credentials in background jobs. Disconnect is a destructive hosted-UI action and requires a newly created session with recent reauthenticatedAt.

Expected result

The returned connected boolean matches the effective status, including time-based expiry.

Handle errors

Do not turn an API failure into disconnected; preserve the tuple error and retry the read with bounded backoff.

Security boundary

Status reads return no credentials. Do not infer identity from a browser path or model input.

Next step

Load user-scoped tools only for effective connected services.