Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] theoretical / experimental take on mongo-backend sessions #13424

Closed
wants to merge 5 commits into from
Closed
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
"codemirror": "^5.42.0",
"coffeescript": "^2.3.2",
"connect": "^3.6.6",
"connect-mongodb-session": "^2.1.1",
"core-js": "^2.5.7",
"csv-parse": "^4.0.1",
"emailreplyparser": "^0.0.5",
Expand Down
24 changes: 24 additions & 0 deletions packages/rocketchat-grant/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,33 @@ import Providers, { middleware as providers } from './providers';
import Settings from './settings';

let grant;
let storeAddress = process.env.MONGO_URL || 'mongodb://localhost:27017/';

if (storeAddress.indexOf('connectTimeoutMS=') < 0) {
faust64 marked this conversation as resolved.
Show resolved Hide resolved
if (storeAddress.indexOf('?') < 0) {
storeAddress += '?connectTimeoutMS=1200';
} else {
storeAddress += '&connectTimeoutMS=1200';
}
}
const SessionStorage = require('connect-mongodb-session')(session);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use import rather than require

const store = new SessionStorage({
collection: process.env.SESSION_COLLECTION || 'rocketchat_grant_sessions',
databaseName: process.env.SESSION_DATABASE || 'rocketchat',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this force the rocketchat database instead of getting from connection URI?

uri: storeAddress,
}, ((e) => {
if (e !== undefined) {
throw new GrantError('Sessions storage initialization failure:', e);
}
}));

store.on('error', (e) => {
throw new GrantError('Sessions storage error caught:', e);
});

WebApp.connectHandlers.use(session({
secret: 'grant',
store,
resave: true,
saveUninitialized: true,
}));
Expand Down