Created
August 12, 2014 14:23
-
-
Save gregfroese/febcc484aa962bf8c88c to your computer and use it in GitHub Desktop.
Protecting routes with authentication in Express
This file contains hidden or 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
var express = require('express'); | |
var router = express.Router(); | |
var bodyParser = require('body-parser'); | |
var jwtauth = require('../../../jwtauth.js'); | |
router.get('/', [bodyParser(), jwtauth], function(req, res) { | |
//jwtauth is run automatically and will populate req.user if there is a valid token supplied | |
if(!req.user) { | |
res.status(401).send({error: "Unauthorized access"}); | |
return | |
} | |
//retrieve your data and pass it back | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment