package com.seer.teach.filter.auth;

import cn.dev33.satoken.reactor.filter.SaReactorFilter;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.util.SaResult;
import com.seer.teach.config.AuthProperties;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;

@Slf4j
//@Configuration
public class SaTokenConfigure {

    /**
     * 注册 [Sa-Token全局过滤器]
     */
    @Bean
    public SaReactorFilter getSaReactorFilter(AuthProperties authProperties) {
        return new SaReactorFilter()
                .addInclude("/**")
                // 指定 [放行路由]
                .setExcludeList(authProperties.getExcludePatterns())
                // 指定[认证函数]: 每次请求执行
                .setAuth(obj -> {
                        log.info("auth",obj);
                })
                .setError(e -> {
                    log.error("auth error",e);
                    return SaResult.error(e.getMessage());
                });
    }
}