Added U and D endpoints.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import MongoStore from "connect-mongo";
|
||||
import session from "express-session";
|
||||
import { mongooseDbName, mongoURI } from "../database/mongoose.js";
|
||||
import userModel from "../schemas/userModel.js";
|
||||
const sessionConf = {
|
||||
secret: process.env.SESSION_SECRET || "super duper secret string.",
|
||||
cookie: {
|
||||
@@ -16,11 +17,12 @@ if (process.env.NODE_ENV === "production") {
|
||||
}
|
||||
export const userSession = session(sessionConf);
|
||||
|
||||
export function authenticationGuard(req, res, next) {
|
||||
export async function authenticationGuard(req, res, next) {
|
||||
if (req.session.userId) {
|
||||
req.user = await userModel.findById(req.session.userId);
|
||||
next();
|
||||
} else {
|
||||
res.sendStatus(401);
|
||||
res.status(401).send("Not authorized.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user