Kolaybase + React: A Backend for Your React App

Give your React app a real backend. With kolaybase-js you query PostgreSQL, authenticate users, and store files directly from your components.

Install

npm install kolaybase-js

Create a shared client

// src/kolaybase.ts
import { createClient } from "kolaybase-js";

export const kb = createClient({
  projectId: import.meta.env.VITE_KOLAYBASE_PROJECT_ID,
  apiKey: import.meta.env.VITE_KOLAYBASE_ANON_KEY,
});

Always use the client-safe anon key in the browser. Row-level security policies decide what each user can read or write.

Load data in a component

import { useEffect, useState } from "react";
import { kb } from "./kolaybase";

export function Posts() {
  const [posts, setPosts] = useState([]);
  useEffect(() => {
    kb.from("posts").select("id, title").then(({ data }) => setPosts(data ?? []));
  }, []);
  return <ul>{posts.map((p) => <li key={p.id}>{p.title}</li>)}</ul>;
}

Talk to the backend directly

Query PostgreSQL from components with filtering, ordering, and pagination built in.

Built-in auth state

Use kb.auth.onAuthStateChange to react to sign-in and sign-out in your UI.

Secured by the database

Row-level security keeps the anon key safe to ship to the browser.

Frequently asked questions

Is it safe to use Kolaybase in the browser?
Yes, with the anon key and row-level security enabled. Policies run in the database, so users only ever read or write rows they're allowed to.
Can I build a custom auth hook?
Yes. Wrap kb.auth.getUser and kb.auth.onAuthStateChange in a React context to expose the current user across your app.

Other integrations

Build your React backend on Kolaybase

PostgreSQL, auth, storage, and a REST API — running in minutes.

Get started