Ver código fonte

fix: frontend login/admin hooks, correct auth route redirects

Signed-off-by: Jonathan <theflametrooper@gmail.com>
Jonathan 4 anos atrás
pai
commit
070a8fc979

+ 1 - 1
frontend/components/Modals/Login.vue

@@ -99,7 +99,7 @@ export default {
 				password: this.password
 			})
 				.then(res => {
-					if (res.status === "success") window.location.reload();
+					if (res.status === "success") window.location.href = "/";
 				})
 				.catch(
 					err => new Toast({ content: err.message, timeout: 5000 })

+ 1 - 1
frontend/components/Modals/Register.vue

@@ -237,7 +237,7 @@ export default {
 				recaptchaToken: this.recaptcha.token
 			})
 				.then(res => {
-					if (res.status === "success") window.location.reload();
+					if (res.status === "success") window.location.href = "/";
 				})
 				.catch(
 					err => new Toast({ content: err.message, timeout: 5000 })

+ 10 - 2
frontend/main.js

@@ -134,9 +134,11 @@ lofig.get("serverDomain").then(serverDomain => {
 				userId
 			});
 		});
+
 		socket.on("keep.event:banned", ban => {
 			store.dispatch("user/auth/banUser", ban);
 		});
+
 		socket.on("event:user.username.changed", username => {
 			store.dispatch("user/auth/updateUsername", username);
 		});
@@ -148,13 +150,19 @@ router.beforeEach((to, from, next) => {
 		clearInterval(window.stationInterval);
 		window.stationInterval = 0;
 	}
+
 	if (window.socket) io.removeAllListeners();
+
 	io.clear();
+
 	if (to.meta.loginRequired || to.meta.adminRequired) {
 		const gotData = () => {
-			if (to.loginRequired && !store.state.user.auth.loggedIn)
+			if (to.meta.loginRequired && !store.state.user.auth.loggedIn)
 				next({ path: "/login" });
-			else if (to.adminRequired && store.state.user.auth.role !== "admin")
+			else if (
+				to.meta.adminRequired &&
+				store.state.user.auth.role !== "admin"
+			)
 				next({ path: "/" });
 			else next();
 		};