0.65.2 • Published 7 days ago

@dzangolab/fastify-firebase v0.65.2

Weekly downloads
-
License
MIT
Repository
github
Last release
7 days ago

@dzangolab/fastify-firebase

A Fastify plugin that provides an easy integration of Firebase Admin in a fastify API.

Requirements

  • @dzangolab/fastify-config
  • @dzangolab/fastify-slonik
  • @dzangolab/fastify-mercurius

Installation

In a simple repo:

npm install @dzangolab/fastify-firebase

If using in a monorepo with pnpm:

pnpm add --filter "myrepo" @dzangolab/fastify-firebase

Usage

Register Plugin

Register the file fastify-firebase package with your Fastify instance:

import firebasePlugin, { initializeFirebase } from "@dzangolab/fastify-firebase";
import configPlugin from "@dzangolab/fastify-config";
import fastify from "fastify";

import config from "./config";

import type { ApiConfig } from "@dzangolab/fastify-config";
import type { FastifyInstance } from "fastify";

// Create fastify instance
const fastify = Fastify({
  logger: config.logger,
});

// Register fastify-config plugin
fastify.register(configPlugin, { config });

// Register fastify-user route
fastify.register(firebasePlugin);

await fastify.listen({
  port: config.port,
  host: "0.0.0.0",
});

Add resolver in your apps resolver collection

import { userDeviceResolver } from "@dzangolab/fastify-firebase";

import type { IResolvers } from "mercurius";

const resolvers: IResolvers = {
  Mutation: {
    ...userDeviceResolver.Mutation,
  },
  Query: {
    ...userDeviceResolver.Query,
  },
};

export default resolvers;

Configuration

Add firebase configuration

const config: ApiConfig = {
  // ...
  firebase: {
    credentials: {
      clientEmail: "...",
      privateKey: "...",
      projectId: "...",
    }
    table: {
      userDevices: {
        name: "user-devices";
      }
    }
    notification: {
      test: {
        enabled: true,
        path: '/send-notification'
      }
    };
    handlers: {
      userDevice?: {
        addUserDevice: (request: SessionRequest, reply: FastifyReply) => Promise<void>
      },
      notification: {
        sendNotification: (request: SessionRequest, reply: FastifyReply) => Promise<void>
      },
    };
  }
};
0.65.2

7 days ago

0.65.1

10 days ago

0.65.0

15 days ago

0.64.2

1 month ago

0.64.1

1 month ago

0.64.0

2 months ago

0.63.0

2 months ago

0.62.4

2 months ago

0.62.3

2 months ago

0.62.2

2 months ago

0.62.1

3 months ago

0.62.0

3 months ago

0.61.1

3 months ago

0.61.0

3 months ago

0.59.0

4 months ago

0.60.0

3 months ago

0.58.0

4 months ago

0.57.1

4 months ago

0.57.0

4 months ago

0.56.0

5 months ago

0.55.2

5 months ago

0.55.1

5 months ago

0.55.0

5 months ago

0.54.0

5 months ago