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

connect-redis no longer compatible with @fastify/session #224

Open
2 tasks done
ctkc opened this issue Nov 27, 2023 · 6 comments
Open
2 tasks done

connect-redis no longer compatible with @fastify/session #224

ctkc opened this issue Nov 27, 2023 · 6 comments

Comments

@ctkc
Copy link

ctkc commented Nov 27, 2023

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.24.3

Plugin version

10.6.0

Node.js version

18.17.0

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

14.0

Description

Trying to make this plugin work with the latest version of connect-redis will fail since express-session is a peer dependency of it since version 7.0.0. RedisStore is extending Store from express-session and also using the SessionData type from it as you can see here: https://github.com/tj/connect-redis/blob/master/index.ts

This leads to the following issue when trying to run a project without express-session installed:

Error: Cannot find module 'express-session'

This can be fixed by downgrading the connect-redis version to v6.1.3

Steps to Reproduce

  1. Set up a project with Fastify, @fastify/session and connect-redis
  2. Run the project
  3. You should get the error message mentioned above

Expected Behavior

No response

@casantosmu
Copy link

Everything is functioning properly. I simply duplicated the contents of examples/redis.js into a new file named /server.js and included the following package.json:

{
  "name": "fastify-session-redis",
  "version": "1.0.0",
  "main": "server.js",
  "scripts": {
    "start": "node ."
  },
  "dependencies": {
    "@fastify/cookie": "^9.2.0",
    "@fastify/session": "^10.6.0",
    "connect-redis": "^7.1.0",
    "fastify": "^4.24.3",
    "ioredis": "^5.3.2"
  }
}

@ctkc
Copy link
Author

ctkc commented Nov 27, 2023

Everything is functioning properly. I simply duplicated the contents of examples/redis.js into a new file named /server.js and included the following package.json:

{
  "name": "fastify-session-redis",
  "version": "1.0.0",
  "main": "server.js",
  "scripts": {
    "start": "node ."
  },
  "dependencies": {
    "@fastify/cookie": "^9.2.0",
    "@fastify/session": "^10.6.0",
    "connect-redis": "^7.1.0",
    "fastify": "^4.24.3",
    "ioredis": "^5.3.2"
  }
}

Hm, that's weird, it doesn't make sense since the library is indeed requesting express-session as a peer dependency. The only possibility I see for not getting the error is having express-session installed globally in your machine.

Before I was trying over NestJs so I tried again following your steps and I'm still getting the same issue as you can see here

Screenshot 2023-11-27 at 4 01 42 PM

For me it makes total sense since I didn't install the library and connect-redis wants to make use of it.

@ctkc
Copy link
Author

ctkc commented Nov 30, 2023

In case someone is experiencing the same issue, I've forked the original connect-redis library and made the necessary changes for it to work with @fastify/session. Anyone is more than welcome to contribute to it.

https://www.npmjs.com/package/fastify-session-redis-store

@mcollina
Copy link
Member

I think it would be likely worthwhile to contribute RedisStore directly to this module. Would you like to send a PR?

@adaboese
Copy link

At a glance, https://github.com/mgcrea/fastify-session-redis-store/blob/master/src/RedisStore.ts looks like it is better implemented.

@adaboese
Copy link

adaboese commented Feb 17, 2024

Could not get @fastify/session to work despite trying for ours. Things like destroying session do not work. TypeScript types are confusing. It is possible that this was an issue with the fastify-session-redis-store not working.

Switched to https://github.com/mgcrea/fastify-session and it worked from first try.

@mcollina maybe deprecate in favor of https://github.com/mgcrea/fastify-session? Seems like a nice ecosystem that's well documented and tested.

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

4 participants