summary refs log tree commit diff
path: root/assets/preload-plugins/loginRedirect.js
blob: 695515b3d46ad8e7fd814d823314f4da07a2175c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if (window.location.hostname == "127.0.0.1" || window.location.hostname == "localhost")
	throw "disabling loginRedirect because localhost";

const redirectIfOnLogin = () => {
	const path = window.location.pathname;
	if (path == "/login" || path == "/register" || !localStorage.getItem("token")) {
		window.location.pathname = "/login";
		window.location.reload();
	}
};

const observer = new MutationObserver((mutations) => {
	redirectIfOnLogin();
});
observer.observe(document, { subtree: true, childList: true });

redirectIfOnLogin();