Al usar AWS re:Post, aceptas las AWS re:Post Términos de uso

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.

preguntada hace 5 meses231 visualizaciones
1 Respuesta
0
Respuesta aceptada

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).

respondido hace 4 meses

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas