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

warn if a mismatched global session is present (fix #47) #52

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/runtime/setup-session.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import Session from './session';
import { warn } from '../shared/log';

export default function setupSession(global) {
const CURRENT_VERSION = 3;
const SESSION_KEY_PREFIX = '_heimdall_session_';
const CURRENT_SESSION_KEY = `${SESSION_KEY_PREFIX}${CURRENT_VERSION}`;

export default function setupSession(global) {
// The name of the property encodes the session/node compatibilty version
if (!global._heimdall_session_3) {
global._heimdall_session_3 = new Session();
if (!global[CURRENT_SESSION_KEY]) {
global[CURRENT_SESSION_KEY] = new Session();
}

for (let i = 1; i < CURRENT_VERSION; i++) {
Copy link
Member

Choose a reason for hiding this comment

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

needs test

let key = `${SESSION_KEY_PREFIX}${i}`;
if (global[key]) {
warn(`Using HeimdallSession Version ${CURRENT_VERSION}, but a global session for HeimdallSession version ${i} also exists!.`);
}
}
}