# firebase-express-dashboard

> [![codecov](https://codecov.io/gh/Asaf-S/firebase-express-dashboard/branch/main/graph/badge.svg?token=HQXFC8JKGX)](https://codecov.io/gh/Asaf-S/firebase-express-dashboard)

Latest version **0.5.2** (published 2022-09-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install firebase-express-dashboard
pnpm add firebase-express-dashboard
yarn add firebase-express-dashboard
bun add firebase-express-dashboard
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.2 |
| Published | 2022-09-24 |
| First published | 2021-03-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 77.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Asaf S. |
| Maintainers | asafs |
| Keywords | firebase, auth, authentication |

## Links

- npm: https://www.npmjs.com/package/firebase-express-dashboard
- Repository: https://github.com/Asaf-S/firebase-express-dashboard
- Homepage: https://github.com/Asaf-S/firebase-express-dashboard#readme
- Issues: https://github.com/Asaf-S/firebase-express-dashboard/issues
- npm.io page: https://npm.io/package/firebase-express-dashboard

## Dependencies (7)

- [cors](https://npm.io/package/cors.md) ^2.8.5
- [express](https://npm.io/package/express.md) ^4.17.1
- [superagent](https://npm.io/package/superagent.md) ^6.1.0
- [typescript](https://npm.io/package/typescript.md) ^4.6.2
- [@types/node](https://npm.io/package/@types/node.md) ^15.0.2
- [firebase-admin](https://npm.io/package/firebase-admin.md) ^9.5.0
- [json-stringify-safe](https://npm.io/package/json-stringify-safe.md) ^5.0.1

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@oxyhq/services](https://npm.io/package/@oxyhq/services.md) — 2.3K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads

## Recent versions

- 0.5.2 (latest) — 2022-09-24
- 0.1.0-0 (next) — 2021-03-20
- 0.5.1 — 2022-09-12
- 0.5.0 — 2022-01-11
- 0.4.5 — 2021-12-20
- 0.4.4 — 2021-08-11
- 0.4.3 — 2021-07-29
- 0.4.2 — 2021-07-28
- 0.4.1 — 2021-07-28
- 0.4.0 — 2021-07-28
- 0.3.14 — 2021-07-10
- 0.3.13 — 2021-07-10
- 0.3.12 — 2021-07-03
- 0.3.10 — 2021-06-21
- 0.3.9 — 2021-06-21
- … 18 more at https://npm.io/package/firebase-express-dashboard/versions

## README

[![codecov](https://codecov.io/gh/Asaf-S/firebase-express-dashboard/branch/main/graph/badge.svg?token=HQXFC8JKGX)](https://codecov.io/gh/Asaf-S/firebase-express-dashboard)

# firebase-express-dashboard

Add CRUD routes that manage Firebase Auth to Express.js.

Also, it exposes a dashboard to manage it all.

See ['src/demo.ts'](https://github.com/Asaf-S/firebase-express-dashboard/blob/main/src/demo.ts) file to see how to better integrate it into your project.

![Dashboard](./screenshot.png)

```javascript
import express from 'express';
import FB_admin from 'firebase-admin';
import firebaseDashboard from 'firebase-express-dashboard';

const serviceAccount = {
  type: 'service_account',
  project_id: process.env.PROJECT_ID,
  private_key_id: process.env.PRIVATE_KEY_ID,
  private_key: process.env.PRIVATE_KEY,
  client_email: process.env.CLIENT_EMAIL,
  client_id: process.env.CLIENT_ID,
  auth_uri: 'https://accounts.google.com/o/oauth2/auth',
  token_uri: 'https://oauth2.googleapis.com/token',
  auth_provider_x509_cert_url: 'https://www.googleapis.com/oauth2/v1/certs',
  client_x509_cert_url: process.env.CLIENT_X509_CERT_URL,
};

const firebaseInstance = FB_admin.initializeApp({
  credential: FB_admin.credential.cert(serviceAccount),
  databaseURL: process.env.DATABASE_URL,
});

express()
  .use('/firebaseDashboard', firebaseDashboard(firebaseInstance))
  .listen(PORT, () => console.log(`Express - Listening on ${PORT}`));
```

Then navigate to either of the following to see the dashboard's UI:

- http://localhost:5000/firebaseDashboard (if the port for development is 5000)
- [https://your_domain.com/firebaseDashboard](https://your_domain.com/firebaseDashboard)

The dashboard's UI can be also be embedded in other websites using an iframe.

# Add permissions:

If the request for the HTML contains a bearer token, then that HTML will use the same bearer token while sending its requests.
This means that the following code should be enough to protect the APIs from unauthorized access:

```javascript
express()
  .use(
    '/firebaseDashboard',
    (req, res, next) => {
      if (req.headers.authorization) {
        const user = authService.convertTokenToUser(req.headers.authorization.replace('bearer ', ''));
        if (user && user.isAdmin) {
          return next();
        }
      }
      return res.sendStatus(401);
    },
    firebaseDashboard(firebaseInstance)
  )
  .listen(PORT, () => console.log(`Express - Listening on ${PORT}`));
```

# Need help with the development of:

- Better UI (React.js cannot be placed in a sub-folder without knowing the sub-folder's name during the build time, if someone can solve this somehow it can help the UI a lot).
- Better UI to list/edit the custom claims.
- Add roles or something of that sort.
- Support paging.
- Support other authentication methods other than Bearer-token.

---
_Source: https://npm.io/package/firebase-express-dashboard · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
