diff --git a/src/main/java/com/guo/learningprogresstracker/config/SaTokenDevConfigure.java b/src/main/java/com/guo/learningprogresstracker/config/SaTokenDevConfigure.java index 049c648..606d2db 100644 --- a/src/main/java/com/guo/learningprogresstracker/config/SaTokenDevConfigure.java +++ b/src/main/java/com/guo/learningprogresstracker/config/SaTokenDevConfigure.java @@ -1,5 +1,6 @@ package com.guo.learningprogresstracker.config; +import cn.dev33.satoken.context.SaHolder; import cn.dev33.satoken.interceptor.SaInterceptor; import cn.dev33.satoken.stp.StpUtil; import lombok.extern.slf4j.Slf4j; @@ -17,8 +18,13 @@ public class SaTokenDevConfigure implements WebMvcConfigurer { // 注册拦截器 @Override public void addInterceptors(InterceptorRegistry registry) { - // 注册 Sa-Token 拦截器,校验规则为 StpUtil.checkLogin() 登录校验。 - registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin())) + registry.addInterceptor(new SaInterceptor(handle -> { + // OPTIONS 请求直接放行 + if ("OPTIONS".equalsIgnoreCase(SaHolder.getRequest().getMethod())) { + return; + } + StpUtil.checkLogin(); + })) .addPathPatterns("/**") .excludePathPatterns("/login"); }