https://github.com/robertjgabriel/firebase-express-middleware
Express middleware that handles the firebase auth for API requests.
https://github.com/robertjgabriel/firebase-express-middleware
authentication firebase firebase-auth node npm
Last synced: 2 months ago
JSON representation
Express middleware that handles the firebase auth for API requests.
- Host: GitHub
- URL: https://github.com/robertjgabriel/firebase-express-middleware
- Owner: RobertJGabriel
- License: other
- Created: 2018-07-19T14:36:35.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-19T16:44:17.000Z (almost 8 years ago)
- Last Synced: 2025-07-30T10:53:26.387Z (11 months ago)
- Topics: authentication, firebase, firebase-auth, node, npm
- Language: JavaScript
- Size: 79.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Firebase Express Middleware [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url]
> Express middleware that handles the firebase auth for API requests.
[](https://badge.fury.io/js/firebase-express-middleware)
> Starting new express firebase project? try out [Express Firebase](https://github.com/antonybudianto/firebase-express-middleware) starter
## Requirements
- Node 7 or higher
- Firebase account
## How to use
1. Install the package.
```sh
npm install firebase-express-middleware --s --d
```
2. Require it in your express routes
```js
const firebaseMW= require('firebase-express-middleware');
router.use('/firebase', firebaseMW.auth);
```
3. Now make sure the client's requests have Authorization header. Example being
```
Authorization: Bearer
```
You can get your token here (https://firebase.google.com/docs/auth/admin/verify-id-tokens) from the client SDK.
4. When requesting, and token is valid, you can get the `user` object from response
```js
router.get('/api/example', (req, res) => {
res.json({
message: `You're logged in as ${res.locals.user.email} with Firebase UID: ${res.locals.user.uid}`
});
});
```
if it fails, you get the following 401 header and response.
```js
{
accessDenied: true,
message: 'Full authentication is required to access this resource.',
cause: 'NOT AUTHENTICATED'
}
```
## Debug mode
By default, the middleware will log and output to console, you can disable them by setting
your environment variable for `DEBUG` to `false`
## License
MIT © [Robert James Gabriel](https://www.robertgabriel.ninja)
[npm-image]: https://badge.fury.io/js/firebase-express-middleware.svg
[npm-url]: https://npmjs.org/package/firebase-express-middleware
[travis-image]: https://travis-ci.org/RobertJGabriel/firebase-express-middleware.svg?branch=master
[travis-url]: https://travis-ci.org/RobertJGabriel/firebase-express-middleware
[daviddm-image]: https://david-dm.org/RobertJGabriel/firebase-express-middleware.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/RobertJGabriel/firebase-express-middleware