From d96d6681231c8f4ac1e19b068535ae09a0ce2c5c Mon Sep 17 00:00:00 2001 From: Madeline <46743919+MaddyUnderStars@users.noreply.github.com> Date: Mon, 26 Sep 2022 13:04:55 +1000 Subject: Bring back loginRedirect but fix it. Also move some assets out of public --- assets/preload-plugins/loginRedirect.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 assets/preload-plugins/loginRedirect.js (limited to 'assets/preload-plugins') diff --git a/assets/preload-plugins/loginRedirect.js b/assets/preload-plugins/loginRedirect.js new file mode 100644 index 00000000..695515b3 --- /dev/null +++ b/assets/preload-plugins/loginRedirect.js @@ -0,0 +1,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(); \ No newline at end of file -- cgit 1.5.1