summary refs log tree commit diff
path: root/assets/preload-plugins
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-26 13:04:55 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-09-26 13:04:55 +1000
commit4cdb547f7608f6832825113fc1f77690e7f5960c (patch)
tree656c6319bf93a5fae39219c7157212d65836040f /assets/preload-plugins
parentRearrange assets a bit, fix anything that uses assets folder (diff)
downloadserver-ts-4cdb547f7608f6832825113fc1f77690e7f5960c.tar.xz
Bring back loginRedirect but fix it. Also move some assets out of public
Diffstat (limited to 'assets/preload-plugins')
-rw-r--r--assets/preload-plugins/loginRedirect.js17
1 files changed, 17 insertions, 0 deletions
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