Skip to content

Session not available in @fastify/http-proxy #388

Open
@stefan1968

Description

@stefan1968

Prerequisites

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

Fastify version

5.1.0

Plugin version

10.0.01

Node.js version

22.0.0

Operating system

macOS

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

Ventura 13.6.6

Description

I'm not 100% sure if this is an issue with fastity/session or fastify/http-proxy.

I can get values from the session on normal routes. For example.

export default async function getImage(request, reply) {
  const id = request.params["*"];
  try {
    const access_token = request?.session?.get('access_token') || null;

However, when I try in the preHandler in http-proxy plugin, it doesn't return anything, it's undefined.

fastify.register(fastifyHttpProxy, {
        upstream:
          process.env.NODE_ENV === "production"
            ? "http://xxxxxx:8080"
            : "https:/xxxxxx/v1/graphql", // Replace with your Docker container's address
        prefix: "/hasura", // The prefix for the proxy route
        rewritePrefix: "/",
        preHandler: (request, reply, done) => {
          const access_token = request?.session?.get('access_token') || null;
          console.log("Got access token from session", access_token);
          done();
        },

I'm setting the trustProxy to true, but still nothing. Like I say - all other routes work.

Any ideas?

Link to code that reproduces the bug

No response

Expected Behavior

The session should be available in the preHandler on @fastify-httpproxy

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions