ingrex-nginx in kubernetes with express node.js does not return req.currentUser This is currentUser middleware:
    export const currentUser = (
      req: Request,
      res: Response,
      next: NextFunction
    ) =&gt; {
 
      if (!req.session?.jwt) {
        return next();
      }
      try {
        const payload = jwt.verify(
          req.session.jwt,
          process.env.JWT_KEY!
        ) as UserPayload;
        console.log(&quot;payload in curretnUser middleware&quot;, payload);
        req.currentUser = payload;
      } catch (err) {
        console.log(
          &quot;error in currentUser middleware in common module&quot;,
          err.message
        );
      }
      next();
    };

this is payload object that logged:
      payload in curretnUser middleware {
      id: '609b356f99a625001a76e65e',
      email: 'test@test.com',
      iat: 1620784495
   }

this is the router in &quot;auth&quot; service:
router.get(
  &quot;/api/users/currentuser&quot;,
  currentUser,
  (req: Request, res: Response) =&gt; {
    // if req.currentUser is not defined it will send undefined
    console.log(&quot;request to api/users/currentuser&quot;, req.currentUser);
    res.send({ currentUser: req.currentUser || null });
  }
);

When request hits this route, this gets logged:
request to api/users/currentuser {
     currentUser: {
     id: '609b356f99a625001a76e65e',
     email: 'test@test.com',
     iat: 1620784495
   }
 }

How ever when I send POST request through postman I get currentUser:null. Somehow kubernetes or ingress-nginx is not attaching &quot;currentUser&quot; to request object and I could not figure out why. This is the nginx-ingress config:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-srv
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.org/client-max-body-size: &quot;4m&quot;
    nginx.ingress.kubernetes.io/use-regex: &quot;true&quot;
    nginx.ingress.kubernetes.io/enable-cors: &quot;true&quot;
    nginx.ingress.kubernetes.io/auth-method: POST
spec:
  defaultBackend:
    service:
      name:
        nginx-ingress-default-backend
        # name: default-http-backend:80
      port:
        number: 80

  rules:
    - host: ticketing.dev
      http:
        paths:
          - path: /api/users/?(.*)
            pathType: Exact
            backend:
              service:
                name: auth-srv
                port:
                  number: 3000
Try using this:- use-forwarded-headers
apiVersion: v1
kind: ConfigMap
data:
  use-forwarded-headers: &quot;true&quot;
metadata:
  name: nginx-configuration
  namespace: default