SolidStart
Run better-supabase as SolidStart middleware and read the caller in queries, actions and API routes.
Community adapter
This is a community adapter. It ships with every release and has a smoke test, but the full test matrix and new guides target the supported adapters. See adapter tiers.
createSolidStart(betterSupabase, options) from better-supabase/solid-start
returns the server with SolidStart helpers. Pass getRequestEvent from
solid-js/web so the helpers find the request inside server functions:
import { createSolidStart } from "better-supabase/solid-start";
import { getRequestEvent } from "solid-js/web";
import { betterSupabase } from "./supabase";
export const bsb = createSolidStart(betterSupabase, {
getRequestEvent,
signIn: "/sign-in",
});import { createMiddleware } from "@solidjs/start/middleware";
import { bsb } from "./lib/server";
export default createMiddleware(bsb.middleware);Register the file as middleware: "src/middleware.ts" in app.config.ts. The
middleware verifies the caller, refreshes the session cookie on navigations and
form posts, and puts db, bsb, auth, memberships and session on
event.locals.
Queries
bsb.require(options) returns the caller and its repositories inside a
"use server" function, or throws the refusal: a redirect to signIn or
mfa, else Problem Details:
import { query } from "@solidjs/router";
import { bsb } from "./server";
export const getNotes = query(async () => {
"use server";
const { db } = await bsb.require();
return db.notes.list({ select: ["id", "title"] }).orThrow();
}, "notes");bsb.locals() returns the request's locals without a check.
Actions
bsb.action(options, fn) returns a server function that takes FormData or a
plain object, validates it with any Standard Schema, and returns an
ActionResult:
import { action } from "@solidjs/router";
import { bsb } from "./server";
import { NoteInput } from "./schemas";
const createNote = bsb.action({ input: NoteInput }, (input, { db }) =>
db.notes.create(input),
);
export const addNote = action(async (form: FormData) => {
"use server";
return createNote(form);
});The middleware runs before the route, so entries that read the final response
(withDbStats, withServerTiming) see an empty one. On Nitro's Cloudflare
presets the bindings seed getEnv; pass platformEnv to read the env
elsewhere.
Last updated on