session icon indicating copy to clipboard operation
session copied to clipboard

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

Open deejaybill opened this issue 1 year ago • 3 comments

Prerequisites

  • [X] I have written a descriptive issue title
  • [X] 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 "[email protected]", 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

deejaybill avatar May 08 '24 22:05 deejaybill

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.

mcollina avatar May 11 '24 06:05 mcollina

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 https://github.com/fastify/session/pull/238

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

rktyt avatar May 13 '24 08:05 rktyt

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.

deejaybill avatar May 20 '24 11:05 deejaybill

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?

niels-van-den-broeck avatar Jul 08 '24 13:07 niels-van-den-broeck

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

mcollina avatar Jul 08 '24 14:07 mcollina

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

Will try my best to find the time.

niels-van-den-broeck avatar Jul 09 '24 10:07 niels-van-den-broeck