Skip to content

@lastshotlabs/slingshot-ssr-tanstack

npm install @lastshotlabs/slingshot-ssr-tanstack

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): SsrRouteSource

Source: packages/slingshot-ssr-tanstack/src/source.ts

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): PolicyCtx

Source: packages/slingshot-ssr-tanstack/src/loaders.ts

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

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

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

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

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(): Plugin

Source: packages/slingshot-ssr-tanstack/src/vite-plugin.ts

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

Configuration for createTanStackRouteSource.

Source: packages/slingshot-ssr-tanstack/src/source.ts

Source: packages/slingshot-ssr-tanstack/src/loaders.ts