search

Home  >  Q&A  >  body text

Nodejs: Correct way to return non-HTML data to browser?

User JWT sent to the browser as an HTTP-only cookie. My question is, what is the best way to communicate the display name and user database ID, etc. to the browser?

I know that information can and does be set in the JWT payload, but isn't it best practice to make that cookie (JWT) unavailable to client-side JavaScript?

I can think of two ways - setting custom response headers, or sending the data as JSON in a