Files
DLE/backend/middleware/session.js

23 lines
691 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const session = require('express-session');
const pgSession = require('connect-pg-simple')(session);
const { pool } = require('../db');
const sessionMiddleware = session({
store: new pgSession({
pool: pool,
tableName: 'session',
createTableIfMissing: true,
}),
secret: process.env.SESSION_SECRET || 'your-secret-key',
resave: false,
saveUninitialized: false,
cookie: {
secure: process.env.NODE_ENV === 'production', // В production должно быть true
httpOnly: true,
maxAge: 24 * 60 * 60 * 1000, // 24 часа
sameSite: 'none', // Для работы между разными доменами
},
});
module.exports = sessionMiddleware;