middlewares.js 769 Bytes
import dotenv from "dotenv";
import multer from "multer";
import multerS3 from "multer-s3";
import aws from "aws-sdk";
import routes from "./routes";

dotenv.config();

const s3 = new aws.S3({
  accessKeyId: process.env.AWS_KEY,
  secretAccessKey: process.env.AWS_PRIVATEE_KEY,
  region: "ap-northeast-2",
});

export const localsMiddleware = (req, res, next) => {
  res.locals.siteName = "my Storage";
  res.locals.routes = routes;
  res.locals.loggedUser = req.user || null;
  // console.log(req);
  next();
};

export const onlyPublic = (req, res, next) => {
  if (req.user) {
    res.redirect(routes.home);
  } else {
    next();
  }
};
export const onlyPrivate = (req, res, next) => {
  if (req.user) {
    next();
  } else {
    res.redirect(routes.home);
  }
};