使用代码注入功能的话可以试试添加下面的代码。
<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>