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

A session is not being created when using connect-mongo and fastify/session in versions later than 10.7.0 #250

Closed
2 tasks done
deejaybill opened this issue May 8, 2024 · 6 comments

Comments

@deejaybill
Copy link

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.27.0

Plugin version

10.7.1+

Node.js version

22.1.0

Operating system

Windows

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

Windows 10

Description

Hi,

if I try to upgrade @fastify/session in my existing project, it won't store the session inside the MongoDB Atlas anymore. The latest version that works fine is 10.7.0. It correctly creates a session inside the store even for the user who isn't authenticated.

When I upgrade to 10.7.1 or the newer one 10.7.2, there are no empty sessions, written inside the store. Even the latest version 10.8.0 won't fix this issue.

To create the MongoDB Store for @fastify/session I'm using the package "connect-mongo@5.1.0", the latest version available.

Let me know if I'm missing something or if you need a sample project to simulate the issue. At this moment, the only thing that works is to revert the package to version 10.7.0.

Thanks in advance.

Link to code that reproduces the bug

No response

Expected Behavior

No response

@mcollina
Copy link
Member

Thanks for reporting!

Can you provide steps to reproduce? We often need a reproducible example, e.g. some code that allows someone else to recreate your problem by just copying and pasting it. If it involves more than a couple of different file, create a new repository on GitHub and add a link to that.

@rktyt
Copy link

rktyt commented May 13, 2024

If you have an https connection, check the following updates.

https://github.com/fastify/session/releases/tag/v10.7.1

fix: use request.protocol to check for HTTPS by @mohd-akram in #238

and see https://fastify.dev/docs/latest/Reference/Server/#trustproxy

@deejaybill
Copy link
Author

Thank you @rktyt for the link to the Fastify documentation you provided.

The issue I was facing was resolved by enabling the Trust Proxy setting.
This is because my solution is composed of three distinct services:

  • The first service is responsible for the UI.
  • The second service serves as the API.
  • The third service is a serverless database hosted on MongoDB Atlas.

@niels-van-den-broeck
Copy link

Ran into this as well when updating from 10.7.0 to 10.7.1.
Enabling trustProxy on fastify resolved this for me as well.

Was kind of surprised that this could happen because of a patch release. Think it wouldn't hurt to clarify this in the docs?

@mcollina
Copy link
Member

mcollina commented Jul 8, 2024

If you would like to send a PR, it would be likely appreciated

@niels-van-den-broeck
Copy link

If you would like to send a PR, it would be likely appreciated

Will try my best to find the time.

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