React SDK

StoreIdentity

This is an interface to provide a <Store>­ with authentication data.

Properties

  • entityRecord EntityRecord

    • Entity record of the authenticated user.
  • client Client

    • An authenticated Client to perform requests against the user’s server.
  • blobUrlBuilder BlobUrlBuilder

    • Synchronous function to get a blob URL from a given record and blob.

The <Store>­ component does not require a specific authentication mechanism and will accept any StoreIdentity regardless of how it’s procured.

In this example, we read the identity from a variable injected on window by an HTML script from the server that generated the page instead of relying on useAuthentication.

import {Client} from "@baqhub/sdk";
import {Store} from "./baq/store.js";

const serverData = JSON.parse(window.serverData);

const client = Client.authenticated({
  entityRecord: serverData.entityRecord,
  appRecord: serverData.appRecord,
  credentialsRecord: serverData.credentialsRecord,
  serverPublicKey: serverData.publicKey,
});

const blobUrlBuilder = await client.buildBlobUrlBuilderAsync();

const identity = {
  entityRecord: serverData.entityRecord,
  client,
  blobUrlBuilder,
};

function App() {
  return (
    <Store identity={identity}>
      <Home /> {/* Rest of the app */}
    </Store>
  );
}
© 2024 Quentez