[Error] 스프링 시큐리티 로그인 시 999 에러

Jin·2023년 9월 9일
0

Error

목록 보기
2/3

구글 로그인은 괜찮은데 네이버 로그인을 하는 경우 999 에러가 발생했다. 로그인이 아예 실패한줄 알았는데 메인 화면으로 이동하니 로그인이 되어 있었다.
해결 방법은 SecurityConfig 클래스의 filterChain 메서드에 아래와 같이 /error 경로로 오는 경우를 permitAll()에 추가하고 로그인이 성공했을 때 기본 경로를 /로 등록하면 된다.

public class SecurityConfig {

    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http
                .authorizeHttpRequests((authorizeRequest) -> authorizeRequest
                        .requestMatchers("/posts/new", "/comments/save").hasRole(Role.USER.name())
                        .requestMatchers("/", "/css/**", "images/**", "/js/**", "/login/*", "/logout/*", "/posts/**", "/comments/**", "/error").permitAll()
                        .anyRequest().authenticated()
                )
                .formLogin(
                        (loginConfig) -> loginConfig.loginPage("/login")
                                .loginProcessingUrl("/")
                                .defaultSuccessUrl("/")
                )
                ...
    }
}
...

참고 페이지
https://stackoverflow.com/questions/49660763/spring-security-login-always-lands-in-an-error-page-with-no-message
https://stackoverflow.com/questions/61029340/spring-security-redirects-to-page-with-status-code-999/61029341

profile
블로그 이사했습니다! 💨💨 https://guswls28.tistory.com

0개의 댓글