summary refs log tree commit diff
path: root/assets/preload-plugins/loginRedirect.js
blob: cda4da448517405090ac98f17e789592b9100a5f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
if (window.location.hostname !== "127.0.0.1" && window.location.hostname !== "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();
}