Skip to content

Commit

Permalink
fix: sessions can get cookies from sessionStore
Browse files Browse the repository at this point in the history
Closes #3
  • Loading branch information
nerdeveloper committed Oct 9, 2019
1 parent 7249c5d commit 0893904
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,20 @@ app.use(express.static(path.join(__dirname, "../public")));
// Takes the raw requests and turns them into usable properties on req.body
app.use(express.json());
app.use(express.urlencoded({extended: true}));

const expiryDate = new Date(Date.now() + 60 * 60 * 1000); // 1 hour
const sessions = {
name: process.env.SESSION_NAME,
resave: false,
cookie: {
expires: expiryDate,
},
saveUninitialized: false,
secret: process.env.SECRET,
store: new MongoStore({mongooseConnection: mongoose.connection}),
};

app.use(session(sessions));
app.use(
session({
name: process.env.SESSION_NAME,
secret: process.env.SECRET,
resave: false,
saveUninitialized: false,
store: new MongoStore({mongooseConnection: mongoose.connection}),
cookie: {
expires: expiryDate,
},
}),
);

// Passport JS is what we use to handle our logins
app.use(passport.initialize());
Expand Down Expand Up @@ -83,4 +84,15 @@ if (app.get("env") === "development") {
app.locals.pretty = true;
}

if (app.get("env") === "production") {
// 500 - Any server error
app.use(function(err: any, req: express.Request, res: express.Response, next: express.NextFunction) {
res.status(err.status || 500);
res.render("error", {
message: err.message,
error: {},
});
});
}

export default app;

0 comments on commit 0893904

Please sign in to comment.