Skip to content

Latest commit

 

History

History
50 lines (37 loc) · 1.51 KB

README.md

File metadata and controls

50 lines (37 loc) · 1.51 KB

Express Firebase Middleware

Express middleware for your Firebase applications.

npm version

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

  1. Install the packages using npm

    npm install express firebase-admin express-firebase-middleware

    Both express and firebase-admin are peerDependencies.

  2. Require it in your express routes

    var firebaseMiddleware = require('express-firebase-middleware');
    
    router.use('/api', firebaseMiddleware.auth);
  3. 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)

  4. When requesting, and token is valid, you can get the user object from response

    router.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