JsonWebTokenError: jwt must be provided

I attaching the backend and frontend both code snippet.
No description
No description
12 Replies
vic
vic2mo ago
Make sure the /signin sends response jwt token data Guess the error in /signin function in backend console logs the response variable and check it contains the token
Ashwani
AshwaniOP2mo ago
@vic It is passing the auth after sign in. But When I redirect the page to "/todo" in frontend, it refreshes the page hits the todo api in the backend again and fails to get jwt. Bcoz I can't send jwt with window.location.href = "http://localhost:3000/todo";
No description
No description
Ashwani
AshwaniOP2mo ago
Please somebody help. I have been googling and gpting, but could get the desired result.
vic
vic2mo ago
Why u need to send the token ? If u set the token in localstorage , u can access in localstorage
Ashwani
AshwaniOP2mo ago
But I can't access localStorage in Node js where the auth runs.
vic
vic2mo ago
Then use cookies
vic
vic2mo ago
Stack Overflow
How to store jwt token in localStorage and send it back to the serv...
I have read many articles in stackoverflow and have seen lots of youtube videos, but failed to find the example code which is demonstrating about the flow of saving jwt to localstorage - send back to
vic
vic2mo ago
Take a look at this Also storing jwt token in localstorage is not a good practice
Ashwani
AshwaniOP2mo ago
Right. Just a beginner's project. Will use lastest processes for auth.
vic
vic2mo ago
Did u try see the headers in /todo path To check whether it has token
Ashwani
AshwaniOP2mo ago
It is available in req headers, checked on browser. I think maybe I am not following the right way to land on todo page after signin.
vic
vic2mo ago
So token is available Try console log in /todo path U need to use spilit the token
Want results from more Discord servers?
Add your server