-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ad3de7
commit 04a69cb
Showing
3 changed files
with
10 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,23 @@ | ||
const admin = require.main.require('firebase-admin'); | ||
import { log } from './util/logger'; | ||
|
||
const logger = require('./util/logger'); | ||
const admin = require.main.require('firebase-admin'); | ||
|
||
function firebaseAuthMiddleware(req, res, next) { | ||
export default function firebaseAuthMiddleware(req, res, next) { | ||
const authorization = req.header('Authorization'); | ||
if (authorization) { | ||
let token = authorization.split(' '); | ||
admin.auth().verifyIdToken(token[1]) | ||
.then((decodedToken) => { | ||
logger.log(decodedToken); | ||
log(decodedToken); | ||
res.locals.user = decodedToken; | ||
next(); | ||
}) | ||
.catch(err => { | ||
logger.log(err); | ||
log(err); | ||
res.sendStatus(401); | ||
}); | ||
} else { | ||
logger.log('Authorization header is not found'); | ||
log('Authorization header is not found'); | ||
res.sendStatus(401); | ||
} | ||
} | ||
|
||
module.exports = firebaseAuthMiddleware; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
const auth = require('./auth.middleware'); | ||
import auth from './auth.middleware'; | ||
|
||
module.exports = { | ||
export { | ||
auth | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
const debug = (process.env.APP_DEBUG === 'true'); | ||
|
||
function log() { | ||
export function log() { | ||
if (!debug) return; | ||
|
||
console.log(...arguments); | ||
} | ||
|
||
module.exports = { | ||
log | ||
}; |