Created
March 9, 2021 14:21
-
-
Save andriangungon/e2a42765d4c278141ecf8e623af33ff9 to your computer and use it in GitHub Desktop.
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
module.exports = function isLoggedIn(req, res, next) { | |
if (req.user) { | |
next(); | |
} else { | |
// return unauthorized | |
res.send(401, "Unauthorized"); | |
} | |
}; |
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
const express = require("express"); | |
const setCurrentUser = require("./middleware/setCurrentUser.js"); | |
const isLoggedIn = require("./middleware/isLoggedIn.js"); | |
const app = express(); | |
app.use(setCurrentUser); | |
app.get("/users", isLoggedIn, function(req, res) { | |
// ... | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment