Skip to content

Client and Auth

There is one deployment-pinned client per app page:

js
import { opencloud } from "/_opencloud/sdk.js";

The singleton owns same-origin runtime discovery, session refresh, request headers, and capability availability. It never exposes access or refresh tokens.

app.info()

ts
app.info(): Promise<{
  id: string;
  version: string | null;
  environment: "dev" | "production";
  visibility: "public" | "private";
  capabilities: {
    auth: boolean;
    data: boolean;
    files: boolean;
    functions: boolean;
    notifications: boolean;
    realtime: boolean;
    telemetry: boolean;
  };
}>

Use capability flags to disable a feature honestly in a development preview. Do not read /_opencloud/config directly.

auth.currentUser()

Returns the current safe profile or null for a signed-out public visitor:

js
const user = await opencloud.auth.currentUser();
if (user) {
  renderIdentity(user.displayName ?? user.email ?? user.id);
} else {
  renderSignedOut();
}

The shape is { id, email, displayName, avatarUrl }. Private apps normally receive an admitted user because OpenCloud handles access at the edge.

auth.requireUser()

Returns the same profile or throws OpenCloudError with code AUTH_REQUIRED and surface auth:

js
const user = await opencloud.auth.requireUser();

Use it before a workflow that cannot proceed anonymously. Data writes, managed file writes, private Functions, and Realtime also enforce their own auth requirements.

auth.signInUrl()

Returns a same-origin URL for a sign-in link and safely preserves the current path, query, and fragment:

js
signInLink.href = opencloud.auth.signInUrl();

It is synchronous and accepts no options. OpenCloud resolves the central Auth origin at the edge; app code never constructs or guesses an Auth URL.

dispose()

Closes Realtime subscriptions and clears cached runtime/session state. Call it when the app itself tears down; individual views should call the unsubscribe function returned by realtime.subscribe().

Self-hosted infrastructure for agent-built applications.