fix: return JSON on logout success instead of 302 redirect to avoid cross-origin redirect
CI/CD Deploy (Admin) / 构建后端镜像并部署 (push) Successful in 49s
CI/CD Deploy (Admin) / 构建后端镜像并部署 (push) Successful in 49s
This commit is contained in:
@@ -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")
|
||||||
|
|||||||
Reference in New Issue
Block a user