Skip to content

Commit

Permalink
init babel and np
Browse files Browse the repository at this point in the history
  • Loading branch information
antonybudianto committed Nov 19, 2017
1 parent 8b0ea22 commit 945804b
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["env"]
}
5 changes: 0 additions & 5 deletions index.js

This file was deleted.

25 changes: 25 additions & 0 deletions lib/auth.middleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

var admin = require.main.require('firebase-admin');

var logger = require('./util/logger');

function firebaseAuthMiddleware(req, res, next) {
var authorization = req.header('Authorization');
if (authorization) {
var token = authorization.split(' ');
admin.auth().verifyIdToken(token[1]).then(function (decodedToken) {
logger.log(decodedToken);
res.locals.user = decodedToken;
next();
}).catch(function (err) {
logger.log(err);
res.sendStatus(401);
});
} else {
logger.log('Authorization header is not found');
res.sendStatus(401);
}
}

module.exports = firebaseAuthMiddleware;
7 changes: 7 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

var auth = require('./auth.middleware');

module.exports = {
auth: auth
};
15 changes: 15 additions & 0 deletions lib/util/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

var debug = process.env.APP_DEBUG === 'true';

function log() {
var _console;

if (!debug) return;

(_console = console).log.apply(_console, arguments);
}

module.exports = {
log: log
};
16 changes: 13 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
"name": "express-firebase-middleware",
"version": "1.0.0",
"description": "Express middleware for your Firebase applications",
"main": "index.js",
"main": "lib/index.js",
"files": [
"lib"
],
"scripts": {
"build": "babel src -d lib --ignore spec.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
Expand All @@ -23,7 +27,13 @@
},
"homepage": "https://github.com/antonybudianto/express-firebase-middleware#readme",
"peerDependencies": {
"express": "^4.15.0",
"firebase-admin": "^4.1.2"
"express": "^4.16.2",
"firebase-admin": "^5.5.0"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-preset-env": "^1.6.1",
"np": "^2.17.0"
}
}
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const auth = require('./auth.middleware');

module.exports = {
auth
};

0 comments on commit 945804b

Please sign in to comment.