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 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则