1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-09-20 01:31:34 +02:00
server/assets/preload-plugins/loginRedirect.js
2022-09-28 17:09:10 +10:00

17 lines
539 B
JavaScript

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();