full-stack-with-react-and-spring-boot icon indicating copy to clipboard operation
full-stack-with-react-and-spring-boot copied to clipboard

Missing axios.interceptors.request config after refresh

Open KosKou opened this issue 6 years ago • 6 comments

Version I'm using the entire project with the backend and frontend from the github repository

Test Case full-stack-with-react-and-spring-boot project backend & frontend clone

Steps to reproduce -Get logged in -List todos page -Check that jwt is being sending into the request as typically -Refresh the page (CTRL+R or F5) -Check that jwt is no longer being sent in the request

Expected Behavior Persist the token header configuration that was set in axios.interceptors.request after every event as refresh page.

Actual Behavior The axios.interceptos.request configuration is getting cleared after refreshing the page so, the request(GET, POST, DELETE) that works with the auth token will not work anymore.

image

Is there anyway to persist the token auth? or keep the axios.interceptors?

KosKou avatar Apr 10 '19 12:04 KosKou

Hey, I got the same problem, have you found a solution yet?

auspham avatar Aug 15 '19 01:08 auspham

I spent a whole day trying to debug this problem and I encountered your post, thanks for letting me know that I am not alone.

rayljc avatar Aug 27 '19 01:08 rayljc

@rayljc I found the solution, sorry thought that no one is following this post so I didn't post.

You can just store the session token by: AuthenticationService.js image sessionStorage.setItem(..)

And in AuthenticatedRoute.jsx modify to something like this: image

auspham avatar Aug 27 '19 02:08 auspham

@rockmanvnx6 Thanks a lot for replying / helping me out, I would definitely try it and wish you a great day.

rayljc avatar Aug 27 '19 02:08 rayljc

Hi @rockmanvnx6 , just want to let you know that your method works for me, even though I use basic authentication instead of JWT. (still, I encounter the refreshing issue.) Below are the screenshots of my codes: image image

And it works! Thanks again for your help.

rayljc avatar Aug 27 '19 04:08 rayljc

It seems to me that we also should remove "USER_TOKEN" in AuthenticationService in "logout" method.

gbucenter avatar Jan 27 '21 09:01 gbucenter