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

Compatibility with express-session #15

Open
gajus opened this issue Nov 13, 2021 · 2 comments
Open

Compatibility with express-session #15

gajus opened this issue Nov 13, 2021 · 2 comments

Comments

@gajus
Copy link

gajus commented Nov 13, 2021

Currently migrating from express-session to this package is pain because of incompatible APIs.

It would be nice if session values should be read / written the same way they are in express-session;

fastify-session (current):

session.set('someValue', 123);
session.get('someValue');

express-session (desired):

session.set('someValue', 123);
session.get('someValue');
@gajus
Copy link
Author

gajus commented Nov 13, 2021

If anyone else comes across this, a simple proxy does most of the job.

session: new Proxy(request.session, {
  get: (target: Session<UserSession>, prop: keyof UserSession) => {
    return target.get(prop);
  },
  set: (target: Session<UserSession>, prop: keyof UserSession, value) => {
    target.set(prop, value);

    return true;
  },
}),

@mtiger2k
Copy link

I also come to this issue. But I have no idea where to put this code?
add it to onRequest hook?

thanks.

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

2 participants