Skip to content

SDK installation

Use a public key in the app. Keep signing keys and privileged transports on your server.

Install

npm install reflet-sdk

The core client needs fetch. Server token helpers need Web Crypto, available in Node.js 18+ and compatible edge runtimes. React entry points require React and React DOM 18 or 19. The Vite plugin requires Vite 5+.

Configure a client

Create an API key in your organization's settings. Add your app's origin to its allowed domains before using the public key in a browser. The client sends it as a Bearer credential on every request.

import { Reflet } from "reflet-sdk";

const reflet = new Reflet({
  publicKey: "fb_pub_YOUR_PUBLIC_KEY",
});

const config = await reflet.getConfig();

Public keys do not unlock internal feedback. Trusted user tokens identify your customers; they do not grant organization membership. For private team access, use team sign-in. For server-side administration, use the HTTP API. Never put a secret key in client props, a public environment variable, source control, or a browser bundle.

Sign a trusted user

Voting, commenting, subscribing, and unsubscribing require a verified external user. Authenticate the request in your app, derive the user ID from that session, then sign it. Do not sign an arbitrary ID supplied by the browser.

Your server
// Server only. Call after authenticating the request in your own app.
import { signUser } from "reflet-sdk/server";

type AuthenticatedUser = {
  id: string;
  email?: string;
  name?: string;
};

export async function createRefletIdentity(user: AuthenticatedUser) {
  const secretKey = process.env.REFLET_SECRET_KEY;
  if (!secretKey) {
    throw new Error("REFLET_SECRET_KEY is missing");
  }

  return await signUser(
    { id: user.id, email: user.email, name: user.name },
    secretKey,
    3600,
  );
}
Your client
import { Reflet } from "reflet-sdk";

// Supply the token returned by your authenticated server endpoint.
export function createUserClient(token: string) {
  return new Reflet({
    publicKey: "fb_pub_YOUR_PUBLIC_KEY",
    userToken: token,
  });
}
  • signUser(user, secretKey, expiresInSeconds?) is asynchronous and returns { token, expiresAt }. Expiration defaults to 86,400 seconds; expiresAt is a millisecond timestamp.
  • Fetch a replacement from your authenticated server before expiration. The SDK does not refresh tokens for you.
  • verifyUser(token, secretKey) is also asynchronous. It returns the user fields or null for an invalid or expired token. Keep verification server-side.
  • The user option creates an unsigned identity. It can attribute a new report, but cannot act as a user established by a signed token or update their profile.

Change or clear identity

// After fetching a fresh signed token:
reflet.setUserToken(token);

// On sign-out:
reflet.setUserToken(undefined);

// Unverified attribution for report creation only:
reflet.setUser({ id: "visitor_123", name: "Visitor" });
reflet.setUser(undefined);

Each setter clears the other identity mode. In React, pass refreshed tokens through RefletProvider; use its context setter for unsigned user state. See provider identity.