@lastshotlabs/slingshot-ssr-tanstack
npm install @lastshotlabs/slingshot-ssr-tanstack
Functions
Section titled “Functions”createTanStackRouteSource
Section titled “createTanStackRouteSource”Build a TanStack-aware route source.
Pass to createSsrPackage({ routeSource }). The plugin will use this for
URL → route resolution and module loading instead of the file-based default.
function createTanStackRouteSource(config: TanStackRouteSourceConfig): SsrRouteSourceSource: packages/slingshot-ssr-tanstack/src/source.ts
getPolicyCtx
Section titled “getPolicyCtx”Resolve the PolicyCtx required by every canX policy function:
the slingshot context (carrier) and the permissions evaluator.
Throws when slingshot-permissions is not registered — that’s a deployment misconfiguration, not a per-request error, so we surface it loudly.
function getPolicyCtx(ctx: SsrLoadContext): PolicyCtxSource: packages/slingshot-ssr-tanstack/src/loaders.ts
loadActor
Section titled “loadActor”Build an Actor from the request’s authenticated user (or anonymous when
unauthenticated). Mirrors the actor shape every canX policy expects.
Performs await ctx.getUser() exactly once; cache the result if you need
it more than once in a single load.
async function loadActor(ctx: SsrLoadContext): Promise<Actor>Source: packages/slingshot-ssr-tanstack/src/loaders.ts
requireActor
Section titled “requireActor”Combined actor + policyCtx fetch. Use when you need both — most authed loaders do.
async function requireActor(ctx: SsrLoadContext): Promise<Source: packages/slingshot-ssr-tanstack/src/loaders.ts
requirePolicy
Section titled “requirePolicy”Gate a loader on a canX(actor, resource, policyCtx) check. Returns
either the forbidden signal (the loader should return it directly —
slingshot-ssr middleware maps it to HTTP 403) or the actor + policyCtx
for use in the rest of the loader.
The check is a function reference, not a name — pass canReadThread,
canModerateContainer, etc. The resource is whatever the check needs
(typically an id or slug).
async function requirePolicy<TResource>(ctx: SsrLoadContext, check: (actor: Actor, resource: TResource, policyCtx: PolicyCtx) => Promise<boolean>, resource: TResource,): Promise<Source: packages/slingshot-ssr-tanstack/src/loaders.ts
requireUser
Section titled “requireUser”Gate a loader on a logged-in user. Returns either the unauthorized signal
(the loader should return it directly — slingshot-ssr middleware maps
it to HTTP 401) or the actor + policyCtx for the loader to use.
async function requireUser(ctx: SsrLoadContext,): Promise<Source: packages/slingshot-ssr-tanstack/src/loaders.ts
stripServerFiles
Section titled “stripServerFiles”Vite plugin: replace .server.{ts,tsx,js,jsx,mts,cts,mjs,cjs} imports with
an empty module in the client build. SSR builds pass through unchanged.
function stripServerFiles(): PluginSource: packages/slingshot-ssr-tanstack/src/vite-plugin.ts
Interfaces
Section titled “Interfaces”PolicyCtx
Section titled “PolicyCtx”Policy context — what every canX() function needs at hand. carrier is
anything the slingshot pluginState helpers accept (typically bsCtx);
permissions is the resolved evaluator.
Source: packages/slingshot-ssr-tanstack/src/loaders.ts
TanStackRouteSourceConfig
Section titled “TanStackRouteSourceConfig”Configuration for createTanStackRouteSource.
Source: packages/slingshot-ssr-tanstack/src/source.ts
Exports
Section titled “Exports”Source: packages/slingshot-ssr-tanstack/src/loaders.ts