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

bug/question: session not being initialized from external when retrieving #206

Open
xxRockOnxx opened this issue Feb 27, 2021 · 0 comments

Comments

@xxRockOnxx
Copy link

https://github.com/koajs/session/blob/6.1.0/lib/context.js#L38

On the linked line from the file above, it's either create new session or initialized from cookie when retrieving a session i.e ctx.session.something.

Why does it not support initializing from external as well (on this specific part of the code. external init is being called somewhere else)?

Is this intended?

An example where this might happen is the following:

const response = request(koaApp).post('/give-me-session');
const cookie = extractCookieFromResponse(response);
const websocket = new WebSocket('ws://<address:port>/ws/use-my-session');

// Websocket Handler
function websocketHandler(req) {
  const ctx = koaApp.createContext(req);
  const authenticated = ctx.session.userId;
}

If I were to use cookies, this would work because of the highlighted line above but otherwise it's going to be a new session.

Is this intended? Is this wrong?

Workaround would be:

async function websocketHandler(req) {
  const ctx = koaApp.createContext(req);
  const sessionId = ctx.cookies.get('koa.sess');
  const sessionData = await koaSessionStore.get(sessionId);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant