bradtraversy / proshop_mern

Shopping cart built with MERN & Redux
1.99k stars 1.18k forks source link

Token expired #179

Closed lanaarnous01 closed 2 years ago

lanaarnous01 commented 2 years ago

in postman says cannot send request and i cannot delete products from the products list please help how can i refresh my token and if i deploy the app is this still going to happen? Thank you

TomaszPietrzykowski commented 2 years ago

log out and in again

lanaarnous01 commented 2 years ago

but in postman it says could not send request Error: Invalid character in header content ["Authorization"]

TomaszPietrzykowski commented 2 years ago

I'm only guessing that you added the script that saves bearer token as env variable in postman upon login so that you don't have to set the headers every time. If this is the case just hit login route again from postman. It will update env variable when receives new token from server just like you overwrite your token in client.

Yes it will happen in production just as well and depends on your token expiration time you set on the server. I belive better user experience could be delivered having check on response and automatically log user out when 401 received. That would remove outdated token from local storage and prevent confusion.

lanaarnous01 commented 2 years ago

i am not setting the header everytime but i just clicked on headers and i recieve an exclmination mark from autherization and when i logged in and out went back to postman for the loggin route and still says doestn send a request and error invalid

TomaszPietrzykowski commented 2 years ago

You should probably move this thread to udemy qna. It is hard to guess remotely. You should have an "Authorization" header with string value of format: "Bearer < token >" on every request that goes through your auth middleware. Try setting it by hand with latest token you got from server upon login.

lanaarnous01 commented 2 years ago

how can i see the latest token from the server?

TomaszPietrzykowski commented 2 years ago

It comes in response body from login route after successful login.

lanaarnous01 commented 2 years ago

Sorry, I am not following, where and how exactly?

TomaszPietrzykowski commented 2 years ago

Consider completing the course first. That will give you understanding of how your application works. It's possible there's no quick fix if you do not know the flow of the app.

lanaarnous01 commented 2 years ago

postman 2

This is the error i keep getting on postman

lanaarnous01 commented 2 years ago

i just want to know from where can i get the new token

TomaszPietrzykowski commented 2 years ago

Token is generated on the backend by authUser controller. To get one from the client you have to send POST request to /login route with valid login and password in request body. You will find a token in response body.

lanaarnous01 commented 2 years ago

postman 2 api error I did the post login but still, the error keeps occurring

lanaarnous01 commented 2 years ago

products collection is working but not the delete products by admin user and auth collection none of the routes are working

alifarukm commented 2 years ago

Please check your bearer token from jwt.io . @lanaarnous01

lanaarnous01 commented 2 years ago

it says invalid signature

lanaarnous01 commented 2 years ago

i copied and paste the bearer token in authorization postman and pasted it in jwt.io and says invalid signature

lanaarnous01 commented 2 years ago

i removed the last character in my token still invalid signature, what can i do

TomaszPietrzykowski commented 2 years ago

You don't need that header for login, you are sending credentials in body. Remove that header, hit login and get new token from backend.

talmax1124 commented 2 years ago

Please continue this in UDEMY

lanaarnous01 commented 2 years ago

i tried removing it but it doesnt allow me its locked