React routing not working on deployed application

0

Hello, I managed to deploy a Spring Boot with React application on AWS Elastic Beanstalk by packaging the application as a single .war archive, putting the frontend (React) build inside the target/classes/static folder. While locally everything works fine, when I try to login inside the newly deployed instance, the application is not able to redirect me to the main page after I put the login credentials, as it would do normally. The frontend console logs states that the redirect was indeed triggered (I used the useNavigate() React hook), but nothing happens as it stays on the same login page. Do you have any idea if it's something related to the S3 bucket not being able to serve the app properly? If I run the .war file locally on localhost:8080 it works by redirecting me to the new page.

已提問 6 個月前檢視次數 234 次
1 個回答
0
已接受的答案

I found the issue, apparently it was not related to AWS but to the way I set the cookie containing the JWT token that I'm using to make requests to the backend.

The issue was that the cookie was not saved on the browser when it got back with the login response and the private route that I'm using was redirecting me to the login page since it didn't find the cookie (as if I was not logged in). Locally it worked, but on the Elastic BeanStalk instance it didn't save the cookie since the connection was not HTTPS.

To overcome the issue and be able to save the cookie on the AWS instance, I sent it from the backend using a Set-Cookie header and also used the read-only property credentials: 'include' on each request I make (including the login one).

已回答 4 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南