RefirebaseRefirebase

The easiest Firebase API

One class for Firestore, Realtime Database, Storage, and Auth. Client hooks, Admin SDK, and Next.js env vars — without the boilerplate.

bun
bun add refirebase

Getting started

Pass config or read FIREBASE_* / NEXT_PUBLIC_FIREBASE_*. Same verbs on client and server.

lib/refirebase.ts
import { Refirebase } from 'refirebase';
const { db, auth } = new Refirebase();
firestore
const users = await db.firestore.get('users', {
  where: { role: 'admin' },
  orderBy: [{ field: 'created_at', direction: 'desc' }],
  limit: 20,
});

const stop = db.firestore.subscribe(
  'conversations/abc/messages',
  (messages) => console.log(messages),
);
auth
// google
await auth.handleProviderSignIn('google');
// better auth
await auth.handleCustomTokenSignIn(serverToken);
// sign out
await auth.handleSignOut();
storage
const uploaded = await db.storage.upload(
  'media/photo.jpg',
  file,
);

const bytes = await db.storage.getBytes(uploaded.path);
refirebase/admin
import { RefirebaseAdmin } from 'refirebase/admin';

const admin = new RefirebaseAdmin();
const token = await admin.auth.createCustomToken(userId);

await admin.db.storage.upload('media/photo.jpg', buffer);

const url = await admin.db.storage.getSignedUrl(
  'media/photo.jpg',
  { expiresSeconds: 60 },
);
refirebase/react
import {
  RefirebaseProvider,
  useCollection,
  useUser,
} from 'refirebase/react';

function Inbox() {
  const { user } = useUser();
  const { data } = useCollection('messages', {
    where: { to: user?.uid },
  });

  return <ul>{data.map((m) => <li key={m.id}>{m.text}</li>)}</ul>;
}

Features

A thin, typed API over the Firebase products you already use.

db.firestore.get(
'users', {
where: { role: 'admin' }
}
)

One-line queries

get, add, set, update, delete — plus where, orderBy, and limit without building Query objects.

subscribe(messages)
hello
photo.jpg
voice

Live updates

Firestore subscribe and Realtime onValue, with onDisconnect for presence.

handleCustomTokenSignIn

Auth that fits Next.js

Google popup, email/password, and custom tokens so Better Auth sessions can unlock Firebase rules.

client
admin

Admin, same shape

refirebase/admin mirrors the client: transactions, signed URLs, createCustomToken.

new Refirebase<Schema>
users: {
email: string
}

Schema generics

Pass a TypeScript schema and collection names autocomplete with the right document type.

NEXT_PUBLIC_FIREBASE_*

Next.js env

Reads FIREBASE_* and NEXT_PUBLIC_FIREBASE_* so the client bundle stays valid.

Covers the Firebase surface

One package instead of wiring each SDK yourself.

Ready in one install

Ship Firebase without the SDK maze

Client, React, and Admin — same verbs, same paths, TypeScript throughout.

bun
bun add refirebase