fix: return JSON on logout success instead of 302 redirect to avoid cross-origin redirect
CI/CD Deploy (Admin) / 构建后端镜像并部署 (push) Successful in 49s

This commit is contained in:
张家训
2026-09-03 18:23:13 +08:00
parent d20fa6ab00
commit 030916e6aa
@@ -1,5 +1,7 @@
package com.freedom.admin.config; package com.freedom.admin.config;
import com.alibaba.fastjson.JSON;
import com.freedom.admin.common.Result;
import com.freedom.admin.service.impl.UserServiceImpl; import com.freedom.admin.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@@ -84,6 +86,14 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.and() .and()
.logout() .logout()
.logoutUrl("/logout") .logoutUrl("/logout")
.logoutSuccessHandler((request, response, authentication) -> {
// 返回 JSON 而非默认 302 跳转 /login?logout,
// 避免前端 axios 跟随重定向触发跨域拦截
Result result = Result.ok().message("退出成功");
response.setCharacterEncoding("utf-8");
response.setContentType("application/json");
response.getWriter().write(JSON.toJSONString(result));
})
.and() .and()
.rememberMe() .rememberMe()
.rememberMeParameter("rememberme") .rememberMeParameter("rememberme")