firebase-elsolya
v1.0.0
Published
Framework-agnostic Firebase (v9+) initializer + small chat/notifications helpers by Elsolya.
Maintainers
Readme
firebase-elsolya
Framework-agnostic helpers for Firebase (v9+):
initFirebase()initializer (SSR-safe: Messaging is lazy)createChatService()(Firestore-backed)createNotificationService()(Firestore-backed)
Install
npm i firebase-elsolya firebase
firebaseis a peer dependency. You must install it in your app.
Quick start
import { initFirebase } from "firebase-elsolya";
const ctx = initFirebase({
apiKey: "...",
authDomain: "...",
projectId: "...",
storageBucket: "...",
messagingSenderId: "...",
appId: "...",
measurementId: "..."
});Chat (Firestore)
import { createChatService } from "firebase-elsolya";
const chat = createChatService(ctx, { collectionPrefix: "prod" });
const room = await chat.createRoom("General");
await chat.sendMessage(room.id, {
body: "Hello!",
type: "text",
senderId: "user_1",
senderName: "Ahmed"
});
const unsub = chat.subscribeMessages(room.id, (messages) => {
console.log(messages);
});Notifications (Firestore)
import { createNotificationService } from "firebase-elsolya";
const notifications = createNotificationService(ctx);
await notifications.addNotification({
title: "New Order",
message: "Order #123 created",
type: "success",
userId: "user_1",
data: { orderId: 123 }
});
const unsub = notifications.subscribeNotifications((items) => console.log(items), { userId: "user_1" });SSR notes (Next.js / Nuxt)
initFirebase()is SSR-safe.- Messaging is lazy: call
await ctx.getMessagingSafe()in the browser.
License
MIT
