就是只要点开网址就是登录页面,如果不登录,什么都看不到,

目前想到两个方案:

  1. 使用全局代码注入功能来实现,插入一段脚本判断当前是不是登录用户,不是的话直接跳到登录页面
  2. 修改下主题模板,在模板中实现上面的逻辑

    使用代码注入功能的话可以试试添加下面的代码。

    <script>
    fetch("/apis/api.console.halo.run/v1alpha1/users/-")
      .then(response => response.json())
      .then(data => {
        let username = data.user.metadata.name;
        if (username == "anonymousUser") {
          let currentUrl = window.location.href;
          let loginUrl = "/console/login?redirect_uri=" + currentUrl;
          window.location.href = loginUrl;
        }
      })
      .catch(error => console.error('Error:', error));
    </script>