Installing the Headless SDK
This guide shows how to add Solis, Prismatic's headless SDK, to your frontend and connect it to Prismatic as a signed-in customer user. After it connects, you can read the marketplace, instances, and connections and render them with your own components.
Before you begin
- Your backend must sign a JWT for each signed-in user, as described in Authenticating embedded users. Solis uses the same token as the hosted embedded SDK.
- Solis runs in the browser.
It doesn't support server-side rendering: during a server render, the React hooks stay
loading.
Install the package
Solis has two packages. Install the one that matches your frontend:
| Package | Use it when |
|---|---|
@prismatic-io/solis-react | Your app uses React 18 or 19. It includes @prismatic-io/solis-core, so you don't install both. |
@prismatic-io/solis-core | Your app uses another framework, or none. |
- React
- Other frameworks
npm install @prismatic-io/solis-react@latest
npm install @prismatic-io/solis-core@latest
Connect to Prismatic
Solis connects to Prismatic through a hidden iframe that it adds to your page. The iframe never renders anything, and your app never calls Prismatic's API directly. You pass Solis two things:
- Your Prismatic URL:
https://app.prismatic.io, the URL of your deployment region (likehttps://app.eu-west-1.prismatic.io), or your custom white-label domain. - The user's JWT: The token your backend signed for the signed-in user.
- React
- Other frameworks
Wrap the part of your app that uses Prismatic in PrismaticProvider:
import { PrismaticProvider } from "@prismatic-io/solis-react";
export function Integrations({ token }: { token: string }) {
return (
<PrismaticProvider
prismaticUrl="https://app.prismatic.io"
auth={{ token }}
onError={(error) => console.error("Prismatic session failed", error)}
>
<IntegrationsPage />
</PrismaticProvider>
);
}
Hooks inside the provider share one session and one cache.
Until the provider receives a token, the session stays loading.
Call createClient with your Prismatic URL and the user's JWT:
import { createClient } from "@prismatic-io/solis-core";
export async function connectToPrismatic(token: string) {
const client = await createClient({
prismaticUrl: "https://app.prismatic.io",
jwt: token,
});
return client;
}
createClient resolves once the iframe is ready and throws a ConnectError if it can't connect within 30 seconds.
Change the limit with the timeoutMs option.
When the user leaves the page that uses Prismatic, call client.dispose() to remove the iframe and release the session.
Refresh the token
Embedded user JWTs expire, so your app needs to fetch new ones while the user is signed in. When it does, pass the new token to Solis. Solis applies it to the live session, so loaded data stays in place. If the new token belongs to a different user, Solis drops the previous user's data.
- React
- Other frameworks
Pass the new token to PrismaticProvider through the auth prop.
Call client.authenticate(newToken) and make later requests through the handle it returns, or through client.authenticated.
Verify the connection
Confirm that Solis connected and accepted the token by reading the signed-in user:
- React
- Other frameworks
import { useAuthenticatedUser, usePrismatic } from "@prismatic-io/solis-react";
function IntegrationsPage() {
const session = usePrismatic();
const user = useAuthenticatedUser();
if (session.status === "error") {
return <p>Could not connect: {session.error.message}</p>;
}
if (user.status === "loading") return <p>Connecting…</p>;
if (user.status === "error") return <p>{user.error.message}</p>;
return <p>Connected to Prismatic as {user.data.email}</p>;
}
const client = await connectToPrismatic(token);
const user = await client.authenticated?.getAuthenticatedUser();
console.log(`Connected to Prismatic as ${user?.email}`);
If the session doesn't connect, check that the Prismatic URL matches the region or domain where your organization lives, and that your backend signs the token as described in Authenticating embedded users.