1

I am new to React and node. I am using React.js and Nodejs. I am doing an Axios POST request where I am sending data and in Node.js, I am creating a JWT token.

Now I want to use this token in auth middleware with the code I have made.

I get data in React.js from Node.js, using res.data. I can't save the data in localStorage or sessionStorage as it is not accessible by Node.js and gives error ReferenceError: localStorage is not defined

How to save the token so that I can get in Node.js?

5
  • You should store your token on the React frontend, this could be a Cookie, localStorage or SessionStorage, then you can send this token to your Node.js backend and verify your token there. Your request could either contain a bearer authorization header or simply send the token in a data object. Commented Oct 4, 2022 at 7:57
  • Can u please explain how to send it from react to node?i am storing in local storage in react but then i cant access it in node Commented Oct 4, 2022 at 8:01
  • You could check this tutorial to get started! :) Commented Oct 4, 2022 at 8:06
  • You try to store it on nodejs probably. But you have to save it on reactjs. Because your frontend is reactjs. If you have to use it, you can get on localstorage and send it with api's header. Commented Oct 4, 2022 at 21:22
  • Yes halil, I stored in local storage i sent it to nodejs using header and it worked...Btw thank u for the help Commented Oct 7, 2022 at 6:23

1 Answer 1

1

You can send it via the request header or even part of the request url, both of which are accessible in nodejs

Sign up to request clarification or add additional context in comments.

1 Comment

Thank u Yisheng Jiang...I got the solution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.