Awesome
Express Firebase Middleware
Express middleware for your Firebase applications.
Starting new express firebase project? try out Express Firebase starter
Minimum requirements
- Node 6 or later
- npm 3 or later
- Firebase account
How to use
-
Install the packages using npm
npm install express firebase-admin express-firebase-middleware
Both
express
andfirebase-admin
are peerDependencies. -
Require it in your express routes
var firebaseMiddleware = require('express-firebase-middleware'); router.use('/api', firebaseMiddleware.auth);
-
Now make sure the client's requests have Authorization header like
Authorization: Bearer <your-client-token>
The client can get the token from their client SDK (Web, Android, iOS Firebase SDK)
-
When requesting, and token is valid, you can get the
user
object from responserouter.get('/api/hello', (req, res) => { res.json({ message: `You're logged in as ${res.locals.user.email} with Firebase UID: ${res.locals.user.uid}` }); });
Debug mode
By default, the middleware will log and output to console, you can disable them by setting
your environment variable for APP_DEBUG
to false
License
MIT