Skip to content

Commit

Permalink
Updated sessions and middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
nidhish-nayak committed Mar 23, 2024
1 parent f71bcc8 commit 2e385e4
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 32 deletions.
3 changes: 0 additions & 3 deletions server/src/controllers/post/addPost.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ export const addPost = async (req: Request, res: Response) => {
const { desc, img, userId, filename } = validationResult.data.body;

if (img) {
if (!req.session.check) {
return res.status(401).send("Unauthorized!");
}
if (!filename) return res.status(401).send("Unauthorized!");
if (!img.includes(prefix.prefixPosts) || !img.includes(filename)) {
return res.status(401).send("Unauthorized!");
Expand Down
3 changes: 0 additions & 3 deletions server/src/controllers/story/postStory.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ export const postStory = async (req: Request, res: Response) => {
}

if (img) {
if (!req.session.check) {
return res.status(401).send("Unauthorized!");
}
if (!img.includes(prefix.prefixStories)) {
return res.status(401).send("Unauthorized!");
}
Expand Down
6 changes: 1 addition & 5 deletions server/src/controllers/upload/upload.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ export const uploadFile = (req: Request, res: Response) => {
if (!req.file) throw new Error("File from multer middleware not sent!");

const file = req.file as Express.MulterS3.File;
if (!file) {
req.session.check = false;
return res.status(401).send("File not found in server!");
}
req.session.check = true;
if (!file) return res.status(401).send("File not found in server!");
return res
.status(200)
.json(config.s3Config.cloudfrontLink + "/" + file.key);
Expand Down
13 changes: 0 additions & 13 deletions server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import express, { type Application } from "express";
import config from "./config/config";
import { zodMiddleware } from "./middlewares/zod.middleware";

import session from "express-session";
import activityRoutes from "./routes/activity.route";
import authRoutes from "./routes/auth.route";
import commentRoutes from "./routes/comment.route";
Expand All @@ -31,18 +30,6 @@ app.use(cookieParser());
// Global catches using zod
app.use(zodMiddleware);

// Session middleware setup
app.use(
session({
secret: config.jwtKey,
resave: false,
saveUninitialized: true,
cookie: {
maxAge: 60 * 10 * 1000,
},
})
);

// Upload to client API
app.use("/api/upload", uploadRoutes);

Expand Down
8 changes: 0 additions & 8 deletions server/src/types/custom.d.ts

This file was deleted.

0 comments on commit 2e385e4

Please sign in to comment.