-
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.
Merge pull request #5 from antonybudianto/dev
Dev
- Loading branch information
Showing
9 changed files
with
32 additions
and
24 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["env"] | ||
} |
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,2 +1,3 @@ | ||
node_modules | ||
lib | ||
.vscode |
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
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import auth from './auth.middleware'; | ||
|
||
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 | ||
}; |