こんにちは
現在のページで表示される唯一の「ログイン」ボタンを押す必要を避けるため、現在、ゆっくりとしたリダイレクトを実装しています。
import { apiInitializer } from "discourse/lib/api";
export default apiInitializer("1.0", (api) => {
api.onPageChange((url) => {
const user = api.getCurrentUser();
let path = url?.startsWith("http") ? new URL(url).pathname : url;
path = path?.replace(/\/+$/, "") || "/";
const allowedAnonPaths = ["/login", "/privacy", "/tos", "/pub/about-this-forum", "/safe-mode", "/pub/accessibility-statement"];
if (!user && !allowedAnonPaths.includes(path)) {
window.location.href = "/login";
}
});
});
これは、リダイレクトしたくないパスを除外するものです。
これは理想的ではありませんが、現在は https://physicswithethan.discourse.diy で運用されています。