Skip to content

Request object not getting modified #531

@agrawalarpit14

Description

@agrawalarpit14

I have a middleware which attaches a UserId to the request object.(similar to the explanation in https://stackoverflow.com/questions/12518132/modifying-express-js-request-object) It functions properly while using the application. But while running frisby the request object is not getting modified.

Following is the middleware I used:

exports.appendUserId = () => {
  return (req, res, next) => {
    try {
      req.body.UserId = this.authenticatedUsers.tokenMap[utils.jwtFrom(req)].data.id
      console.log("UserId:", this.authenticatedUsers.tokenMap[utils.jwtFrom(req)].data.id)
      console.log("req.body.UserId:", req.body.UserId)

      req.body.UserId = 1
      console.log("req.body.UserId:", req.body.UserId)

      next()
    } catch (error) {
      res.status(401).json({ status: 'error', message: error })
    }
  }
}

Expected Terminal Output:

UserId: 2
req.body.UserId: 2
req.body.UserId: 1

Present Terminal Output:

UserId: 2
req.body.UserId: undefined
req.body.UserId: undefined

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions