Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backend/.development.env
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ JWT_SECRET=MySuperSecretJwtSecret

TEMPORARY_JWT_SECRET=MySuperSecretTemporaryJwtSecret

# session secret for storing ai history
# you need it if you want to use openai service
# required if OPENAI_API_KEY is set
SESSION_SECRET=MySuperSecretSessionSecret

# for authorization with google
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Messages } from '../../exceptions/text/messages.js';

export function requiredEnvironmentVariablesValidator(): void {
const requiredParameterNames: Array<string> = [
'DATABASE_URL',
'PRIVATE_KEY',
'JWT_SECRET',
];
const requiredParameterNames: Array<string> = ['DATABASE_URL', 'PRIVATE_KEY', 'JWT_SECRET'];

if (process.env.OPENAI_API_KEY && process.env.OPENAI_API_KEY.length) {
requiredParameterNames.push('SESSION_SECRET');
}

const requiredParameters: Array<{ [k: string]: string | null }> = requiredParameterNames.map((paramName) => {
const paramValue = getEnvironmentVariable(paramName);
return {
Expand Down
31 changes: 17 additions & 14 deletions backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,23 @@ async function bootstrap() {
app.use(cookieParser());

const cookieDomain = process.env.ROCKETADMIN_COOKIE_DOMAIN || undefined;
app.use(
session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
cookie: {
secure: true,
domain: cookieDomain,
maxAge: 2 * 60 * 60 * 1000,
httpOnly: true,
},
name: 'rocketadmin.sid',
}),
);
const sessionSecret = process.env.SESSION_SECRET || undefined;
if (sessionSecret) {
app.use(
session({
secret: sessionSecret,
resave: false,
saveUninitialized: false,
cookie: {
secure: true,
domain: cookieDomain,
maxAge: 2 * 60 * 60 * 1000,
httpOnly: true,
},
name: 'rocketadmin.sid',
}),
);
}

app.enableCors({
origin: [
Expand Down