basefyio + React: A Backend for Your React App
Give your React app a real backend. With basefyio-js you query the database, authenticate users, and store files directly from your components.
Install
npm install basefyio-jsCreate a shared client
// src/basefyio.ts
import { createClient } from "basefyio-js";
export const bf =createClient({
projectId: import.meta.env.VITE_BASEFYIO_PROJECT_ID,
apiKey: import.meta.env.VITE_BASEFYIO_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 { bf } from "./basefyio";
export function Posts() {
const [posts, setPosts] = useState([]);
useEffect(() => {
bf.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 your database from components with filtering, ordering, and pagination built in.
Built-in auth state
Use bf.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 basefyio 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 bf.auth.getUser and bf.auth.onAuthStateChange in a React context to expose the current user across your app.
Other integrations
Build your React backend on basefyio
database, auth, storage, and a REST API — running in minutes.