feat: PostgreSQL session store

Replaces MemoryStore with connect-pg-simple.
Sessions now persist across Arbiter restarts.
Table 'session' auto-created if missing.

Signed-off-by: Claude (Chronicler #61) <claude@firefrostgaming.com>
This commit is contained in:
Claude (Chronicler #61)
2026-04-05 10:34:44 +00:00
parent d9b54187ee
commit bc66fec77a

View File

@@ -2,11 +2,13 @@ require('dotenv').config();
const express = require('express');
const expressLayouts = require('express-ejs-layouts');
const session = require('express-session');
const PgSession = require('connect-pg-simple')(session);
const passport = require('passport');
const DiscordStrategy = require('passport-discord').Strategy;
const { Client, GatewayIntentBits, REST, Routes } = require('discord.js');
const csrf = require('csurf');
const cors = require('cors');
const { Pool } = require('pg');
const authRoutes = require('./routes/auth');
const adminRoutes = require('./routes/admin/index');
@@ -16,6 +18,15 @@ const { registerEvents } = require('./discord/events');
const { linkCommand } = require('./discord/commands');
const { initCron } = require('./sync/cron');
// PostgreSQL connection pool for sessions
const pgPool = new Pool({
user: process.env.DB_USER,
host: process.env.DB_HOST,
database: process.env.DB_NAME,
password: process.env.DB_PASSWORD,
port: process.env.DB_PORT || 5432
});
// Initialize Discord Client
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers] });
registerEvents(client);
@@ -64,6 +75,11 @@ app.use(express.urlencoded({ extended: true }));
app.locals.client = client;
app.use(session({
store: new PgSession({
pool: pgPool,
tableName: 'session',
createTableIfMissing: true
}),
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,