Ao usar o AWS re:Post, você concorda com os AWS re:Post Termos 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.

feita há 5 meses231 visualizações
1 Resposta
0
Resposta aceita

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 há 4 meses

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas