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

Request object not getting modified #531

Open
agrawalarpit14 opened this issue Jul 10, 2019 · 8 comments
Open

Request object not getting modified #531

agrawalarpit14 opened this issue Jul 10, 2019 · 8 comments
Labels

Comments

@agrawalarpit14
Copy link

agrawalarpit14 commented Jul 10, 2019

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
@H1Gdev
Copy link
Collaborator

H1Gdev commented Jul 11, 2019

@agrawalarpit14

This code is server side.
How is frisby used on client side ?

@agrawalarpit14
Copy link
Author

agrawalarpit14 commented Jul 17, 2019

Hi!! @H1Gdev Yes, the code is server side. Actually, here some values are attached to the request object after the req comes from the client side before actual processing is done.

Here frisby is used for checking the server side only.

You can take a look at the codebase here, if it helps.

Thank You!! so much

@vlucas
Copy link
Owner

vlucas commented Jul 18, 2019

Are you sending the appropriate headers with JWT tokens from Frisby also?

@agrawalarpit14
Copy link
Author

Yeah, it's the exact same as I use on my frontend calls.😅

@vlucas
Copy link
Owner

vlucas commented Jul 19, 2019

On the front-end, the browser is probably forwarding along cookies that have been set after you login. In Frisby, you have to set these yourself manually. Have you done that?

@agrawalarpit14
Copy link
Author

Hi @vlucas If I am ryt, cookies won't make any difference in this request(We don't use cookies in this component of the project).

@JoshuaConcon
Copy link

Following, I'm also having the same problem. I can only attach things under req.headers but can't attach under different property names (e.g. req.cookies)

@vlucas
Copy link
Owner

vlucas commented Aug 15, 2019

Oh I see. So this is code in Express.js that is somehow not working properly when hitting the API endpoint with Frisby.js? It seems pretty unlikely that Frisby.js itself would be the cause. Are you able to replicate this with another tool like Curl, HTTPie or RequestBin?

Frisby does not automatically save and re-use cookies from previous requests, so that might be the root issue here...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants