I have a very similar question to this. My Spring boot backend has formLogin configured using this Bean :
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.formLogin();
http.authorizeRequests().anyRequest().authenticated();
return http.build();
}
My React app is running port 3000, while the backend is running on port 8080, how can redirect unauthenticated requests to localhost:3000/myLoginPage
?
After reading some SO questions, i wana point out that changing the port for the React app by modifying the package.json like so :
"scripts": {
"dev": "next dev -p 8080",
is not a viable solution in my case, the app wont run since the backend is running on port 8080.
My goal is to redirect the user to another application ( the React app ) and change the default login page generated by spring.
CodePudding user response:
specify loginPage in formLogin
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.formLogin(formLogin -> formLogin.loginPage("http://localhost:3000/myLoginPage"));
http.authorizeRequests().anyRequest().authenticated();
return http.build();
}