Skip to content

Instantly share code, notes, and snippets.

@andriangungon
Created March 9, 2021 14:21
Show Gist options
  • Save andriangungon/e2a42765d4c278141ecf8e623af33ff9 to your computer and use it in GitHub Desktop.
Save andriangungon/e2a42765d4c278141ecf8e623af33ff9 to your computer and use it in GitHub Desktop.
module.exports = function isLoggedIn(req, res, next) {
if (req.user) {
next();
} else {
// return unauthorized
res.send(401, "Unauthorized");
}
};
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